What practice is considered the best one when i have to translate an aggregation/composition of an UML Diagram drawn in Design Phase in implementation phase?
In many cases, when aggregation or composition has been used in a UML class diagram, it just means an association and doesn't have any additional meaning. So, the simple advice is: just translate an aggregation/composition of a UML design model to an association and implement it with suitable reference properties in the implementation (model).
You may want to read my article Really Understanding Association, Aggregation, and Composition.
As Thomas noted, I dont think there are any clear generally aplicable best practices. There's just so many different situations and different contexts which strongly affect selected approach.
Aggregations and compositions are analytical constructs and should not appear in design or implementation models very often, if at all.
What can be said is, that many people struggle to understand the meaning/semantics of aggregation/composition. Usually they tend to over-identify aggregations and compositions. These are in fact rather rare relationships within SW system models. Not every 1:N relationship is an aggregation.
Related
I understand the differences between the three( or at least I think I do). I know there are many other similar questions with definitions like this one.
I was looking an example from gliffy.com and I am strugiling to understand why some releationship were used they way they were used. I guess what I'm really struggling with is understanding when to use association.
Some of the questions I have are:
Why is Customer-Order and Customer-Credit Card an association an not aggregation like Customer-Address?
Why is Order-ItemOrder not composition given that ItemOrder would not exist without an Order?
Why is ItemOrder-Item not aggregation?
In order to answer these questions, it is important to know why this class diagram is drawn. Only the author knows, but maybe it is just a demonstration of the capabilities of gliffy? Otherwise, maybe the classes in this model correspond to classes in source code, written in an object-oriented language like Java or C# and that the diagram is aimed to give insight in the relationships among these classes.
Why is Customer-Order and Customer-Credit Card an association and not aggregation like Customer-Address?
Apparently, the author does not regard these relationships to be 'part-of' relationships. Maybe Customer does not have any reference to Orders or CreditCards in the source code. Maybe Address information belongs to the responsibility of class Customer, but Order and Credit Card information do not.
Why is Order-ItemOrder not composition given that ItemOrder would not exist without an Order?
Maybe the author only uses a subset of UML and does not use composition by convention. Maybe the author thinks the difference between aggregation and composition is not important to convey for the purpose of this diagram.
Why is ItemOrder-Item not aggregation?
Apparently, the author does not regard this relationship to be a part-of relationship. Maybe the author has reserved the aggregation type of relationship to represent one particular programming language construct, which is not used in this case in the source code. Maybe the author has the opinion that an interface can never be aggregated in another class.
By the way, the aggregation between ItemOrder and ShoppingCart is clearly wrong. I think the diamond should be on the other side of the relationship.
Simply forget about shared/composite aggregation. It does have a low semantics and just leads to futile discussions whether it's needed and where it's used right or wrong. Just use (and interpret) the association and multiplicity.
The (almost) only place where you could use aggregations in a meaningful way is in DB foreign key (force delete) and memory (free unused) management.
I am not sure if this is a good question as I'm unsure if there's any agreement on the subject. However due to the lack of information in the internet I'm compelled to ask anyways.
Let's say I'm making a system that is mainly object-oriented, with its corresponding UML diagrams (use-case, class, colaboration, etc). However, none of the UML diagrams are helpful when dealing with the database, which should be relevant for the developing team so they can know what exists in the database and what does not.
There are two ways to represent a database: Entity-Relationship and Relational (it's unknown to me if there are more, but those two are relevant within the relational database paradigm). ER deals with the representation of the BD in terms of business rules, and Relational deals with the actual, physical implementation. But none are "UML standard" (unless I'm missing something here).
Which modeling should I use, and why? Is ER relevant in terms of UML, or should I stick to relational? Thank you beforehand.
If you want to use UML only, you could use limited class diagrams - without m-n associations and methods. But if you are using some class-table mapping tools, you can use anything, except m-n relationships only.
Nobody had ever said that you can use Class diagram for OOP classes only. You can use them for any more or less formal concepts, if their needs can be covered by the complex of CD elements. I use class diagrams for UI planning and even formal text planning. And tables are very close to classes. So, no problem.
You can use data model diagrams, if you need something that is CALLED data diagram. But they are covered by class diagrams fully. That is the reason they are not supported anymore.
Your task is to make the model understandable for everybody, who can get it in hands. Class diagram is the most widely known UML diagram. A good title and a pair of comments will resolve all possible misunderstandings.
Both are different ER diagrams are relationship of entities and UML diagrams are behaviour of Ojects how they communicate with each other, as per my view point DFD (data flow diagram) is option. It has different levels which is based on number of processes and will better explain about data entities.
I would like to know if somebody has a good sample about how to organize a UML class diagram when using Domain-Driven Design.
I really don't know how to make fit entities with repositories and services.
The UML diagrams that I end up with for DDD are usually hand drawn, informal and don't strictly adhere to all the guidelines. From the perspective of UML, entities, repositories and services are all simply classes; classes could be marked with a stereotype for clarity.
Furthermore, I don't place too much emphasis on class diagrams alone. It is often more fruitful to consider the model from a behavioral perspective, which is where sequence diagrams can be helpful, though they can quickly become too technical. Class diagrams can help you identify aggregates and entities, but they can also lead you astray by placing too much emphasis of the nouns as opposed to the verbs.
Another important type of diagram in DDD is a context map which can be viewed as a class diagram for bounded contexts. There aren't any explicit UML practices for expressing context maps and as a result an informal approach works best.
Overall, what has worked for me is low friction, low ceremony, and informal. Use boxes to represent concepts and lines between them to represent relationships. Anything beyond that can certainly be helpful but it shouldn't be at the cost of the other aspects.
You should also understand the purpose of the diagram. Are they for facilitating the design and modeling process? Are they for documentation? For sparking conversation? For communication? Each of those reasons may have specific constraints.
my suggestions: build stereotype for each DDD building block (e.g. <>, <, <> e.t.c.), sign each class by one of this stereotypes, use only "use" connection... (composite only for aggregate)
I've always avoided using aggregation because it seems so subjective which one-to-many relationships should be classed as aggregations. But I'm reviewing a model produced by someone else in which aggregations are used for many-to-many relationships (as in: a course consists of several modules, a module may be part of several courses). That strikes me as plain wrong, but I can't find a definitive rule against it. What's the official ruling?
Two things:
Are shared aggregations allowed? According to the UML spec, yes.
Is it useful in practice? Generally I'd say no.
I am not a fan of the UML Aggregation relationship. Whilst ownership is intuitively appealing, it is too subjective practically. I don't use it, and generally don't recommend it be used (although see footnote). Instead, focus on the important questions:
What's the cardinality?
What's the create/delete behaviour?
Why does the relationship exist? (i.e. what business fact/rule is the relationship capturing?
All above can be done with straight associations. If the answer is (a) it's one to many, (b) the 'one' end is responsible for creating/deleting the 'many' end and (c) you really want to, then use the Composite association. Aggregation however doesn't generally improve readability of the model, it adds confusion and detracts from surfacing the underlying domain rules/requirements.
hth.
footnote: there is one scenario where Aggregation does have well-defined semantics and can be useful. Specifically, if you have a recursive relationship, Aggregation says the resultant object structure is acyclic (i.e. a DAG). Downside is relatively few people realise that property - certainly not business domain experts. So you typically have to highlight anyway, e.g. in a comment / constraint.
A good website for this is
http://www.uml-diagrams.org/class-diagrams.html
If you search there for "Shared and Composite Aggregation" you will read, that shared parts can be modeled as aggregations. Even if the composite holding the part will be discarded the parts are allowed to survive.
This seems to make many to many relationships possible. For example sharing a part of a view for several view-components. Why not...
Personally this matches my understanding, that UML is very interpretative.
Let's set the terms. The Aggregation is a metaterm in the UML standard, and means BOTH composition and shared aggregation, simply named shared. To often it is named incorrectly "aggregation". It is BAD, for composition is an aggregation, too. As I understand, you mean "shared".
Again, if we'll look at the UML standards (look for Superstructure documentation there), we'll find, that "Precise semantics of shared aggregation varies by application area and modeler." So, ANY strategy you choose is acceptable. And you even can use different strategy for different projects.
But the shared aggregation IS useful and CAN be used with multiplicities on both sides and even the empty diamond can be on both sides.
The association in UML is an abstraction, that can be realized in any language and in any way, only the realization must be up to the diagram.
Such association, as on the diagram, can be realized as following:
Every instance of Student has a list of courses he is registered to,
and every instance of Courses has a list of registered
students/participants.
But this is not the only way of realization. There could be arrays instead of lists, and even somebody can make it without any normal collection at all - simply using the addresses in memory in C++.
Of course, we could draw two associations, one for student's list of courses and the second for courses' list of students. But thus:
our diagram becomes more complex and, therefore, less readable.
we are describing thoroughly the elementary things that any coder will do anyway in 99% cases.
we are limiting the freedom of coders. And in 1% of cases they'll have to choose between not following the diagram and not coding effectively. It is simply not your job.
So, do as you wish. Forbidden is only to change the strategy during one project and to FORBID others to use their only strategy.
I am asking if it is necessary or useful to have semantic variances in UML. Would it not be more useful when it was more formal and therefore verifiable or even used for rapid prototyping. What is the benefit of the variance? Can you give some examples?
I would prefer to get rid of the semantic variation points of the UML. A typical example that causes confusion when I model diagrams is the multiple classification semantic variation point. When modeling generalizations in a class diagram, you can choose to assume that the diagram admits multiple classification (an object can be instance of two or more classes not related by a subtype relationship) or not.
Usually designers with a background programming implicitly assume that this is not possible while at the conceptual level many of us tend to implicitly assume that this is possible. You can imagine the result.