1

I currently have a set of components named DataValues, ValueParsers, ValueFormatters and ValueValidators. The first one defines an abstract base class DataValue and contains a whole load of implementations. The 3 other components each define in interface similar to their name (minus the "s"), and also contain a bunch of implementations of those. These 3 depend on DataValues. There are no further dependencies.

In other words, each component currently contains a whole inheritance hierarchy. I recently re-watched EP16 of Robert C. Martin's Clean Coders, where he points out this is one of the most common mistakes made in package design. This made me realize that this exact thing is going on for the here described packages.

The question then is how to best improve upon the current component design. Luckily none of those components have seen their first release yet, so things can still be moved around, and boundaries can still be redefined. Releases for these are on the horizon though, so I better get it right now.

What I'm thinking of doing now is to create a new component to hold the mentioned abstract class and interfaces for all these components. It would also contain the Exceptions of these components and perhaps some trivial implementations of the interfaces.

This new component would then be needed by all the current ones, and by all the ones needing the current ones. Then again, in this later category, there will be a number components that can just depend on the new and get rid of their current dependency on the much more concrete and unstable ones containing all the interface implementations.

This is great for the stable dependencies principle, and equally nice for the reuse release equivalence principle. It's however doing rather bad when it comes to the common closure and common reuse principles. Concretely this means that components that need the ValueParsers interface but don't care about the ValueValidators one will still depend on it as it is in the same package. They can thus be affected by it for no good reason. Then again, considering how abstract/stable this new component ends up being, I don't really see this causing much problems.

I'm looking for ideas on how to better draw the component boundaries and concerns or suggestions about the alternative I described.

4
  • 1
    Not an answer, but this screams over-engineering. Your types are so generic to be meaningless. Focus on a problem, fix the problem.
    – Telastyn
    Commented Jul 15, 2013 at 1:19
  • 1
    I see your concern, though do think there is good reason for this approach in the context I am encountering. That is a whole different discussion though, so I'd prefer this question to be answered under the assumption that this is not over-engineering to begin with. Commented Jul 15, 2013 at 13:37
  • So for every implementation of DataValue you have an implementation of ValueParser,ValueFormatter and ValueValidator? So intruducing a new DataValue implementation requires the introduction of three more classes? Commented Jul 24, 2013 at 11:29
  • No, the DataValue component has no dependency whatsoever on any of the other ones. And there certainly is not a one-to-one relation between implementations of mentioned interfaces. Commented Jul 24, 2013 at 21:29

1 Answer 1

0

After discussing this with colleagues and getting a line of advise from Robert C Marin himself, I settled for the following satisfactory approach:

One component holds the interfaces for DataValues, ValueParssers, ValueValidators and ValueFormatters. This component also holds things such exceptions and implementations of these interfaces that are both trivial and general.

A second component holds the general but more complex implementations of these interfaces.

Making just this split already gets rid of most of the problems we currently have. The first component is very abstract and stable, and is required by a lot of other components. The second component is concrete and instable, and is needed only by a few components.

Further splitting of this second component might happen at a later point. And not all new concrete classes that derive from those interfaces will end up being it it, some might go into new or other existing components.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.