I answer this picture with composition Car 0.1 - Engine 1.1.
Is it true?
Can someone explain about relation Car and Engine?
The question is somewhat confusing since the title mention composition, but not the question you try to answer in the blue box.
We can deduce from the statement in the blue box:
"A Car has exactly one Engine" means 1..1 on the Engine end of the association.
The fact that a Car has an Engine and is not an Engine eliminates option (c), since the generalization represents an is-a relationship.
"An Engine has at most one Car" means 0..1 on the Car end of the association.
But "at most" implies that it could be less, so in other words, you can have an Engine with no Car. This makes option (b) somewhat ambiguous, since 1) the composition implies Engine to be owned by a Car which is responsible for its existence and storage; 2) nevertheless UML allows a part to be removed from the composite and survive independently (see note page 110 that clarifies this point); 3) but the composition symbol might mislead readers about the responsibilities regarding detached parts.
This leaves us options (a) and (d):
option (a) technically fulfils the requirements: the composition in that diagram says that Car cannot exist without an Engine, but the Engine can exist without a Car. However the semantics of UML composition say it is a part- whole relationship, where then Engine would be the whole and the Car the part. This is nonsense, which eliminates option (a)
option (d) technically fulfils the requirements: it is a normal 0..1/1..1 association. The open arrow says that this association is navigable from the Car to the Engine. It leaves unspecified whether the association is navigable in the opposite direction. The navigation is additional information which is not in the narrative, but it doesn't contradict it.
In conclusion, option (d) is the best one that validly fulfils the requirements. It just adds some more information about the association.
Option (b) would be acceptable, but does not appear a natural use for composition in view of the perceived ambiguity for some reader regarding the responsibilities for detached parts.
Related
I have short question about class diagrams. In my book we have class Person and class Gender and agregation arrow between them(with diamond pointing to person). Now, in general when I want to decide whether we have agregation or not I am using one of these two rules:
1.When you destroy class that is whole, than part can exist without it;
2.Class that is part in agregation relation, can be mutual to one or more wholes.
Now if we look at this example and rule number 2, it is OK, because one gender is mutual to one or more persons. But for the first one, if there is not person, than we can't talk about gender right?So I would set composition here. Probably I am missing main difference between these two. Any help is appriciated.
In general
Your rule about when using aggregation is not wrong. But it's unnecessarily complex. There is a simpler much simpler rule about when you'd better use aggregation: never.
This may sound provocative, but the hard truth is that the meaning of aggregation is not defined in the UML specifications, which makes it ambiguous and subject to a lot of unnecessary time-consuming debates:
Sometimes a Property is used to model circumstances in which one instance is used to group together a set of instances; this is called aggregation. (...) Precise semantics of shared aggregation varies by application area and modeler.- UML specifications 2.5.1, page 112.
I know, it comes as a shock. For years in my career, I have myself selected very carefully aggregation whenever there was a part-whole relation with non-exclusive ownership. But when I came accross James Rumbaugh famous quote, I challenged my own assumptions and realized how vain and subjective this quest was:
Keep in mind that aggregation is association. Aggregation conveys the thought that the aggregate is inherently the sum of its parts. In fact, the only real semantics that it adds to association is the constraint that chains of aggregate links may not form cycle (...) In spite of the few semantics attached to aggregation, everybody thinks it is necessary (for different reasons). Think of it as a modeling placebo.- James Rumbaugh in Unified Modeling Language Reference Manual, chapter 14.
So, whenever you have aggregation in a model, you could simply replace it with an association without real loss of information.
In your specific example
The association: Person ----- Gender expresses perfectly that a person has a gender, and that several persons can share the same gender.
If you want to be super-accurate, you could use the dot notation (with a small dot on Gender side). This would convey the information that Person owns the end of the association.
Composition would definitely be wrong here, because it's an exclusive ownership and no two persons could share the same gender.
Aggregation is ambigous: what is the whole, what is the part? If gender is a part, wouldn't character be a part as well. And what with the name, then ?
A final remark: if you want to implement this with Person having a gender:Gender property (an OOP mechanism called "object composition") the, you don't need aggregation (even if it's a popular practice).
Please Look at the following example:
1) The chairs are made of wood .
2) Paper is made from trees .
3) Biogas is produced by the fermentation of waste.
4) Asphalt is produced through the refining of petroleum.
Should these be Composition or Dependency?
In general
You can exclude UML composition: composition implies an exclusive ownership. But chairs are not the only products made of wood.
Dependency is either too much (once the biogas is made, there is no dependency to waste anymore) or not enough (the wood of the chair is part of the chair; it's a stronger relationship than a need-to-know-about).
Moreover it is not clear if you want the Chair to be a class on its own or an instance of a class product.
Specific cases
"Made of" expresses a relationship with parts that make a product. A typical pattern here is the bill of material. The relation is a simple association. Some people tend to use UML aggregation, but UML specifications do not define precisely the semantics, so leave it out to avoid ambiguity.
Here a (very simplified) diagram:
"Made from" expresses a transformation process, where some of the original products disappear in the process and others are created. Paper is made from cellulose which is extracted from trees. But the original tree is not in the sheet of paper.
Typically in process industries, like chemicals, this is represented by a "recipe", which is a sequence of inputs (waste) and operation to obtain products (biogas) and co-products (fermented residual waste). In other industries, this is represented by a "routing" that is a sequence of operations performed on a BOM (in this case, the BOM would not only contain components as previously shown, but also raw products that are transformed by the operations in the routing).
I will not show a diagram because this is quickly very complex, but again, it'll use simple associations.
In the end, "made of" and "made from" would both be represented in UML with associations. But only the semantic that you attach to it will change.
I don't think that any "made of" is represented by some static relation. To make a wooden chair it just Depends on wood. There is no other relation here because you have some complicated process to turn wood into a chair. Or a tree into paper. Or anything else of your choices. In order to describe the relation you would need to describe the process. This is possible using activities. You could as well descibe physical components with UML. But that would take us too far apart from your question...
You might search for answers on composition here. But even these can be looked at controversial. Modeling reality yields a model. Which is not reality.
Your question highlights the difference between an ontology and an information model or application design. For example, in a conceptual ontology (which accounts for necessary and possible situations in the world rather than for data formats of observations and measurements), every person has a mother. In a particular database or application, that knowledge is usually irrelevant. What stuff is made of and how it is produced belongs more to a conceptual ontology, for which UML is not quite expressive enough. This is why languages such as First Order Logic (FOL) and OWL are used instead, and why some tools (such as my company’s) plug holes in UML. (One example of a hole in UML is the inability to express exactly the intersection of two classes.)
I have the following UML containing the class School which (in my example right now) can only have one TeacherRoom.
My Question now is what is the official notation for this UML or should i remove the <<use>> assosiation because it is obvious?
Obvious because i am saving a instance of TeacherRoom in my School instance?
I would define it like that:
The fact that you have attribute teacherRoom : TeacherRoom in class School implies that School is using TeacherRoom, so the ≪use≫-dependency is not needed.
You also have a composition association to TeacherRoom. This means that, in addition to the attribute, you have a second relationship with TeacherRoom. So you may remove either one.
According to my understanding of section 10.4 of UML 2.5.1 specification, Usage dependency decribes the fact that a given Component requires an Interface or Services.
So I would remove it, as this has nothing to do with the fact that a "School" is composed of "TeacherRoom".
My second point is your "teacherRoom" property which has more or less the same meaning than your composition so I would remove one of them (Property or Composition).
Since you wrote
can only have one [typo corrected by me] TeacherRoom.
you need to add a multiplicity 1 to the right of the association (and as commented and answered to remove the diamond). Also rather than an attribute in School you should use a role name teacherRoom at the association and make it an owned property by adding a dot.
Some additional remarks to composition: Composition is (my personal impression) something that causes more confusion than it actually helps building models (just look for questions asking about its semantic and/or look out for wrong usage of it). Even worse is the shared aggregation which caused (and causes) even more confusion. Now after many editions, UML 2.5 defines that hollow thingy as what it is: nothing. Just read the box on p. 110. So back to the filled one, the composite aggregation. Basically it's about lifetime of objects, so whether there's an owner of an object who is responsible of its lifetime. When you make a car composed of its wheels, that's obviously not right since the wheel will live on without being attached to the car. Only the car is no longer a car. But that will be expressed by attaching a multiplicity of 4 to the wheel. Any car with not exactly 4 wheels is no longer a car. No composition at all.
So where can you use composite aggregation then? I have only 2 applications in mind. One is for storage managent. Something that had been important in the early days of computing when dinosaurs like me fought along with hard disks at cupboard size that had 20 Megabytes! Only a few border cases still need indication for memory management. The second case would be security. Indication that something has to be deleted along with its parent. And that's still valid. But then this is the only real application for composite aggregation.
According to UML specs every Element can have an owner. Whether he has/must have an owner is determined by method mustBeOwned(): Boolean, which by default is true (see 7.8 Classifier Descriptions in specs).
In cases when an element is completely enclosed by its owner (such as a class in a package) it is quite obvious.
However for relationships (normal, directed, generalization, …) I didn't find any specification. Is the "source" (for directed at least) also the owner?
Is it the first common owner in the ownership chain? So for example association between two classes in a same package, the owner of the association would be the package.
Or is it simply not defined and it can be whatever I want?
To be honest, the definition of terms in Superstructures is still very poor.
Looking closer it's even worse (citing from ptc 13-09-05).
Relationships (p. 15)
A Relationship is an Element that specifies some kind of relationship between other Elements. Descendants of Relationship provide semantics appropriate to the concept they represent.
Connector (p. 235)
A Connector specifies links that enables communication between two or more instances. In contrast to Associations, which specify links between any instance of the associated Classifiers, Connectors specify links between instances playing the connected parts only.
I wasn't aware that they made a difference between both. Appears to be quite picky.
Association (p. 206)
An Association classifies a set of tuples representing links between typed instances. An AssociationClass is both an Association and a Class.
No mentioning of Relationship as being a parent.
Now seeking for the truth about owner
owner (p. 37)
/owner : Element [0..1]{union} (opposite Element::ownedElement) The Element that owns this Element.
mustBeOwned (a bit down)
mustBeOwned() : Boolean
The query mustBeOwned() indicates whether Elements of this type must have an owner. Subclasses of Element that do not require an owner must override this operation.
So here one is stuck unless reading to
Association (p 209)
Ownership of Association ends by an associated Classifier may be indicated graphically by a small filled circle, which for brevity we will term a dot. The dot is to be drawn integral to the graphic path of the line, at the point where it meets the Classifier, inserted between the end of the line and the side of the node representing the Classifier. The diameter of the dot shall not exceed half the height of the aggregation diamond, and shall be larger than the width of the line. This avoids visual confusion with the filled diamond notation while ensuring that it can be distinguished from the line. The dot shows that the model includes a Property of the type represented by the Classifier touched by the dot. This Property is owned by the Classifier at the other end. In such a case it is normal to suppress the Property from the attributes compartment of the owning Classifier.
Answer?
Most likely (!) connectors do not have the mustBeOwned constraint and can be owned in which case you will see the dot that has been introduced with 2.5. Else they are probably not owned.
To my understanding, the relation is generally not owned by elements it connects. What is owned is the association (relationship) end's and corresponding attributes/properties. Section 6.4.2. of UML specification 2.4.1 clarified this much better than your linked 2.5 beta. I would suggest that you use the current official version of specs rather than the beta one. I find the 2.5 being kind of unintelligible, the table of contents looks very chaotic.
The Relationship itself exists independently, it has no owner. Except when stated otherwise by concrete type of relationship (as in case of Generalization).
Which brings me to the main point of my answer by question. Why do you need to know?
I have been reading and explaining the specification for years now, but never came across such a specific question, which moreover is relatively clearly stated in the specs.
I would recommend to look at concrete relations and search (Ctrl+F) for "owned" (an Association has more than a page of text on this very topic in detail starting on page 40 in 2.4.1).
I myself have been trying to figure out what can own an instance of Association. I am using 2.4.1. This appears to me to be a(nother) case of the standard not actually being usable.
I haven't looked at all of the specializations of Relationship. I have looked at Association. It inherits owner from Element. The property is noted as a derived union. I can't find any property of Association (or any of its antecedents) that subsets owner. That being the case, I don't see how Association can actually have an owner.
I think that it seems reasonable for a Package to own an association.
I am using a UML tool that certainly does initialize the value of owner for associations. I am programmatically interpreting models created in that tool and using them as input for other modeling tools that I am working on. The makers of the first tool obviously had to just make up / guess at things and now I have to decide whether what they did was actually rational and if I want to agree with their conclusions (which happen to allow Classifiers to own Associations, which I think is weird) or do something else. Thanks OMG. Grrrr.
I wonder if older versions of the spec were any more clear?
Except for the context of UML,if A extends B,then B is a subset of A.
But in UML, it's the opposite,say,if A extends B,then A is a subset of B,
why is it so strange?
The <<extend>> dependency is only used for Use cases. It means that one use case extends the other under certain circumstances. In the following:
The client views account details. Under certain circumstances, the client may also "View Open Orders" as part of "View Account Details". It's also possible that the client will "View History" as part of "View Account Details".
This has nothing to do with generalization / specialization.
<<extend>> is confusing in use case diagrams. The smallest part of the confusion is that use case diagrams are not use cases!
A use case is a document, not a diagram. For example, the diagram above might have been drawn from the following use case text:
Client views account details.
Extensions:
1a. If client clicks "Open Orders" link
Client views open orders
1b. If client clicks "View history" link
Client views history
In a more-detailed model, these "extension points" would be listed on the "View Account details" use case element on the diagram. But this clutters the diagram terribly, in my opinion.
I first really learned UML by reading "UML Distilled" by Martin Fowler. I just checked that book before posting this answer, and found that Fowler suggests ignoring <<extend>>.
To write it in terms of use cases (I believe this is context you meant - if not, correct me), lest think about ordering a meal in your favorite fast food restaurant.
Basic use case is to order a meal, but it can be extended if you present a discount coupon. Every time you go trough this use cale, you get a meal, but only under special circumstances you pay less than usually (or get an extra sandwich).
I found quite a good example here: http://www.agilemodeling.com/essays/useCaseReuse.htm. As you can see enrolment for international student includes additional security check, and is applied only to a subset of enrollments. Hope that will help more.
UML doesn't use the term "to extend/extension". Instead, it uses the term "to generalize/generalization"; people also often refer to it as "to inherit/inheritance".
If B is a generalization of A (i.e. A inherits from B), then A is a subset of B. This should become clear from the "is-a" relationship: if every A is a B, then A is clearly a subset of B. In your terminology, if A extends B, A is a subset of B.
A type is a predicate: for every object, you can determine whether it belongs to the predicate. Extending the predicate means to make it more restrictive.