There may be quite a lot of questions concerning the variations between UML Affiliation, Aggregation and Composition on the market and lots of many solutions, some sensible and a few phylosofical. Right here I am asking we speak about sensible variations!
In some solutions I discovered:
- Reference languages like Java cannot actually implement Compositions, for the reason that occasion life cycle is managed by the rubbish assortment;
- Associations and Aggregations haven’t any sensible distinction, so we must always simply drop Aggregations and work with Associations and Compositions; nonetheless, these two sorts of relationship exist;
- These three ideas make sense solely in programming languages like C++, which have an instance-based (and never reference-based) object mannequin;
- Aggregation permits many house owners, Composition doesn’t; a number of sources advogate completely different.
Nevertheless, no reply I’ve discovered to this point approached these ideas within the context of persistent objects. No examples got contemplating persistence, regardless that it’s a very standard growth situation.
When an object is persevered in a database system we do have a life cycle mannequin free from rubbish assortment since an occasion (or desk row if you’ll) deletion occurs in response to a deliberated act from some a part of the software program implementing some product requirement.
The distinction between Affiliation and Composition is certainly very clear, they may produce completely different annotations in code. A really noticiable distinction is that with a Composition we could have cascade delete enabled, so when the Proprietor id deleted, the Gadgets are additionally deleted. In Affiliation there isn’t a cascade delete enabled.
Nevertheless, what variations will we discover when annotating Affiliation and Aggregation, specifically, when in each instances we’ve a cardinality greater than 1?