Note that I am using C# here, but it may not be necessary to provide input to my conceptual questions about design. Consider the following design methodology...
I work at a place where we have a number of different versions of a particular product. Recently I was given a design specification for 3 of the versions, wherein the specification states that the 3 versions are identical except that each has a different name. While I was only given a specification for the 3 versions, there are actually more than just 3. I need to begin writing a base-class object per the design specification. For the sake of this question, I will refer to the base class of this product as
ProductObject contains 16 objects which for the sake of this question I will refer to as
EntryObject. Each of the 16
EntryObject(s) will need slightly different member fields, but are more or less loosely based on the same thing.
The appropriate version of
ProductObject will be constructed with a string of "double-space" separated bytes, which I will refer to as
SeparatedBytes will always have the same format, a header followed by the string of bytes. No matter how many different versions of
ProductObject, the incoming
SeparatedBytes will always be identical except with varying payloads. The payloads are just sensor readings and do not have anything to do with how the data actually looks in terms of format (will always look like a string of bytes separated by a double-space). Here is how
01 EF AB 02 ... XX
This string of "double-space" separated bytes will be parsed/split and passed on to their respective
EntryObjects. Each of the 16
EntryObject(s) will be constructed as one 32-bit word worth of the
SeparatedBytes. So construction of
EntryObject should look like:
EntryObject myEntryObject = new EntryObject("01EFAB02");
The first 4 bytes will be the first type of
EntryObject, the second 4 bytes will be the second type of
EntryObject, the third 4 bytes will be the third type of
EntryObject, up until the sixteenth type of
EntryObject. This will look something like...
EntryObjectType1 type1 = new EntryObjectType1("12345678"); EntryObjectType2 type2 = new EntryObjectType2(the next four bytes); EntryObjectType3 type3 = new EntryObjectType3(the next four bytes); . . . EntryObjectType16 type16 = new EntryObjectType16(the final four bytes);
Proposed Design/Inheritance Hierarchy
I plan on tackling my design in the following manner, in having a namespace consisting of the following:
- Have a base-class for the
- Construct 3 child-classes for each of the
- Have a base-class for the
- Have 16 derived child-classes from the
- Have 16 public
EntryObjectmembers within the
My concern is mainly with #5 here. I am concerned with #5 because I was only given the first 3 versions of
ProductObject to work with.
What if, down the road a new version of
ProductObject comes along and the
EntryObject(s) within, behave differently? Will I be able to accomodate such a change properly, given my proposed design hierarchy?