Search code examples
umlassociationsclass-diagram

dependent class or normal class?


I have a class with several attributes. Among these there is an optional one, applicable only under certain conditions. To avoid the presence of many null attributes, you could detach the optional attribute in a class. In this case, the class with only the optional attribute is a weak class or a normal class? Obviously, detaching the attribute from the class will not mark the attribute as optional but the multiplicity that connects the new class with the old one. multiplicity (1,1) and (0,1)


Solution

  • First let me state, that UML as such does not define such thing as a weak class. So from the UML perspective, it's a normal class.

    Now when it comes to realisation, the dependent would be a weak class.

    However, before applying such approach, you should ask yourself if you really benefit from the design. Yes, you may not have many nulls (but what's wrong about them?) but whenever you need that additional attribute, you need to join tables/create a substructure.

    In the end, the decision is in the architect's hand. I would say the initial design should just show the optionality and conditions and then the actual decision on using optional attribute vs null class depends on other factors than just the fact of many nulls. This has to be weighed for each case individually, however I would say there are very few cases when building a weak class rather than allowing those nulls would be beneficiary.