I have some standard which changes in time. Let's say I have std_v1, std_v2 and std_v3. Those standards have a lot of common parts with some little differences, possible additions and deletions. On top of those standards, I have several concrete implementations, which have a small number of changes.

Right now my class hierarchy looks like:

          /       |      \
      std_v1   std_v2   std_v3
    /        \
 concrete1   concrete2  ...

Where base class collects similarity between std_v1, std_v2, std_v3.

I have some problems with such implementation. For new standard, I need to tweak base class and sometimes previous standard classes to reflect similar code. There is some code in a base class which is used only by one standard. Concrete classes look more than configurations which override public methods, like:

public get_some_data():
    return "concrete_data1"

Is there a better way to improve architecture? I thought about composition but can't figure out how to fit it.

  • Why is one code base supporting multiple standards? Normally I would just branch old versions of the code base off then let them die a natural death. – btilly Apr 5 '18 at 21:38
  • You could investigate the Strategy Pattern en.wikipedia.org/wiki/Strategy_pattern – Ben Apr 6 '18 at 3:21
  • 1
    Seems like good example of caveats of inheritance. In your case inheritance coupled different implementations. If you remove abstractions and use only concrete classes with some duplication, you can have freedom to make changes. – Fabio Apr 6 '18 at 5:11
  • @btilly I need to support different standards, I would say it different projects in one code base – Viacheslav Kondratiuk Apr 6 '18 at 8:13
  • If "concrete classes look [like] configurations", why not make them configurations? Create a common class for the common part, and the rest, dynamically added objects that vary depending on the "standard". – Frank Hileman Apr 9 '18 at 22:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.