Qualifier concept in ddd - domain-driven-design

According to Eric Evans, associations should
Impose a traversal direction
Add qualifiers and reduce multiplicity
Not be present if it is non-essential
I am not able to understand qualifier concept, how do we add to reduce multiplicity. Can any body explain with example.

this is general oop. read more here and here

Related

In UML, does composition imply an association class?

In a UML diagram where one class is comprised by another class, is there an implicit association table, or does it need to be shown?
For example, if I have Chapters that are composition of Paragraphs, is this alone enough:
Or does the association class to be explicitly shown like so:
I've never seen it done like that latter example, so I'm assuming it's implied. Or maybe I haven't normalized the data properly (considering chapter both appears in the Chapter class and the Paragraph class).
Simply, there is no implication. If you need an association class, you need to define it. However, UML is not about diagraming, it's about modeling. You can omit your association class in a diagram if you want to. The association class will still exist in your model, though.
No, it is not implied.
The reason why you haven't seen this is that in most cases it simply doesn't make sense. In the association class the class part additionally describes the properties of the association. In your example you create an artificial object that actually brings little or nothing. This kind of approach can be useful for many-to-many relationships which are impossible for composition (each part can have at most one whole). Even if you wanted to show Foreign Key it would simply be on one of the classes. But that's implied by the association itself. According to UML specification an inline attribute is equivalent to an association.
Moreover on UML you can depict many to many relationship simply but applying appropriate multiplicities on association ends. You may want to show the class depicting that only when modelling on the code level.
No, it is not implied.
UML is not about tables, but about classes. The author of the class diagram should tell the audience how a class should be interpreted. Some UML diagrams model the real world, others model a piece of application functionality and yet others depict a physical implementation.
Apparently, reading your question, you are modeling a relational database, where a class is a physical table. In that case, I would expect that every table is explicitly modeled as a UML class.
The UML standard does not demand this.
By the way, the notation (PK) and (FK) is not in accordance with the UML standard.

Why are association, aggregation and composition used the way they are used in this example?

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.

Does OCL work with composite structure diagrams?

Is OCL meant to be used in combination with a composite structure diagram?
Or does it not make sense? If it makes sense, could someone give a quick example for a possible OCL constraint, e.g. based on this example diagram source ?
UML specifically mentions such situation (section 7.6. of specs)
Constraints themselves can be attached to any kind of UML Element, or in fact a collection of Elements.
And finally:
7.2.1
The root concepts of Element and Relationship provide the basis for all other modeling concepts in UML.
Which means that you can add constraint to anything.

Domain-Driven Design Class Diagram

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)

Associations' traversal direction

I'm reading the book on Domain Driven Design of Eric Evans - Chapter 5, concerning associations. One of his advices to reduce complexity of a model is to impose a traversal direction for the associations.
I quote:
It is important to constrain relationships as much as possible. A
bidirectional association means that both objects can be understood
only together. When application requirements do not call for traversal
in both directions, adding a traversal direction reduces
interdependence and simplifies the design. Understanding the domain
may reveal a natural directional bias.
How to chose a traversal direction for an association? Generally, when there is an association between two elements, it may be read and understood in the two directions. What may cause us to chose one direction over the other?
Thanks
When there's an association between entity A and entity B, you'll often find yourself using only A.B and never B.A. This may be because A is an aggregate root and is always your starting point, because you already have a reference to its A wherever you manipulate a B, etc.
I guess Evans simply suggests that you should add a traversal direction only when you need it and will use it in the code just after, as opposed to prematurely adding a traversal direction "in case we need it later".
Conceptually all associations are bidirectional. Nevertheless, when implementing them most end up being unidirectional since then you just need to maintain the links in one of the participants.
During design you may want to indicate the navegability to break the bidirectionality at the implementation level and facilitate the coding of the system

Resources