[Context: new for Java, 4 months; old hand in C ++.]
I am working on a library that requires a fixed-size array ("fixed string") in many places. I am trying to use Dependency Injection (qv) for this specific problem, so I would like something like a form:
class Foo
{
private Bar injectedBar;
private char[] injectedFixedString;
Foo(Bar injectedBar, char[5] injectedFixedString);
{
A simple one is required - this happens in an automatically generated communication protocol. I have zero control over the protocol and the database from which it is derived; I will have hundreds, if not thousands, of these instances in the final code. So, considering all this:
I am the only C ++ alternative:
char injectedFixedString[5];
create custom class? Sort of:
class FixedBarString {
public static integer STRING_SIZE = 5;
char[] fixedString = new char[STRING_SIZE];
FixedBarString(char[] string) throws RuntimeException {
}
public void setString(char[] string) throws RuntimeException {
}
public char[] getString() {
}
public char[] createBlankString() {
return new char[STRING_SIZE];
}
}
Thank. (My apologies if this is too much code).