Hello,
Have a class, which has a data member that can take on two different personalities:
1.) Null, "N/A" (or any of it's variants).
2.) A non-negative int.
3.) Two non-negative ints representing a range.
I'm currently storing this as a string, which is validated
by a validator object, using regex's before creating the object.
This seems like a prime opportunity to subclass, but the object itself doesn't have very many methods, and subclassing to fork encapsulated data instead of behaviour seems very weak.
Is another object called for that wraps the notion of this mutating data member? (with a hasA() method?) Is there a way to avoid wasting the allocation of a string and two ints for every parent?
Using java, so no C++ Unions. Should I continue to use a validated String? The objects are generated from a file created by an outside organization, so changing the inputs isn't an option, regardless of how nice it would be...
TIA
Have a class, which has a data member that can take on two different personalities:
1.) Null, "N/A" (or any of it's variants).
2.) A non-negative int.
3.) Two non-negative ints representing a range.
I'm currently storing this as a string, which is validated
by a validator object, using regex's before creating the object.
This seems like a prime opportunity to subclass, but the object itself doesn't have very many methods, and subclassing to fork encapsulated data instead of behaviour seems very weak.
Is another object called for that wraps the notion of this mutating data member? (with a hasA() method?) Is there a way to avoid wasting the allocation of a string and two ints for every parent?
Using java, so no C++ Unions. Should I continue to use a validated String? The objects are generated from a file created by an outside organization, so changing the inputs isn't an option, regardless of how nice it would be...
TIA