Question
Can the weak entities of the er diagram also be represented in the class diagram?
Is it possible to represent weak entities in the class diagram as in the er diagram? could stereotypes be used?
Question
Is it possible to represent weak entities in the class diagram as in the er diagram? could stereotypes be used?
Solution
There is no such thing like a weak entity in UML.
The closest design in UML is the composite aggregation (colloquially called composition, i.e. black diamond), with a 1 multiplicity on the diamond side (owning class). This specifies that instances of the component classes are necessarily linked to an instance of the composite (owning) class and cannot exist without. It also tells something about ownership and responsibility for lifecycle of the component class. However this has several drawbacks:
One workaround is to make identifiers more explicit ans specify a composite identifier for the component class. This can be done with db design stereotypes, or just by explicitly specifying a composite id including the id of the owning class, both marked with the {id}
specifier. But the semantics of this specifier are not defined in the UML standard. So, although it conveys the same notions than a weak entity, it may still be ambiguous for a third party reader.
Another solution would indeed be to define a soecific stereotype. One could imagine «weak»
for the class. However I'd rather advise for a «identifying»
on the composite association, to show unambiguously which is the master and which is the dependent (one could even think to use tagging values for this stereotype to
specify the common id attribute, something more difficult with a class stereotype).