Can inherited arity be overriden? - uml

I have this class/object diagram:
I don’t understand why that object diagram is invalid according to the given class diagram.
In the object diagram, one C object has two links with two T objects, alpha relationship with a T object and beta relationship with another T. So I don’t think it violates the multiplicity constraints.
Could you please explain me why the object diagram is invalid?

Yours is the most interesting question I've seen here in a long time. It is pretty tricky!
The simple reason your instances are incorrect is that every instance of type T must be associated with one C. The top instance of type T in your diagram violates the constraint in association beta. (The multiplicity on the left end of the association.)

There are two faults in the object diagram.
There is only a formal fault in the object diagram, the lines in the objects diagrams between the instances are links, i.e., instances of the associations shown in the class diagram. As the links are instances, the same rules for instance naming apply as to class instances. So change alpha to :alpha and underline it, it is correct. Same for beta.
Further the links are not correct, as there is an beta link from the uppermost T instance missing. Each object of A, and as C is a specialization of A, also C (and B) objects need an alpha link to an S instance. As S is a generalized T, an alpha link between A (or one of its specializations) and S (or one of its specializations) is needed. Further each S (or T) might have arbitrary alpha links to A objects.
Each C object needs to have zero or one beta links to T instances. In the other direction, each T instance needs exactly one C instance via a beta link. This is missing for the uppermost T instance.

Leaving my prior answer below, but thinking twice, the answer is that your class diagram is incomplete.
The two alpha and beta associations have no association-end names. The fact that they have different multiplicities leads to the conclusion that they must be different associations. With names it would look like this:
Expanding the inheritance will make this:
Based on this assumption, my original answer stands like this:
The reason is that a :C has two associations alpha and beta each to another :T object. Not a single alpha to one and a single beta to another. So you need to add a beta to the alpha and vice versa.
Edit And yes, JimL. is correct. Having two alpha-links violates the constraint from the class diagram. So actually you can only have one T linked to C. Which again makes the class model very strange.
The C class has a beta-association to T. C inherits from A and T inherits from S. Since there is a alpha-association from A t0 S this is also inherited. So you have:

Related

Can a part (component) class be a member of two assembly (collection) classes?

How would you represent a relationship where an instance of a class is part of two (or more) instances of different classes?
I guess your wording is incorrect, since this has got nothing to do with instances. If a class is referenced in two collections you simply have two associations:
C is referenced from B as attribute c with a multiplicity *. Dito for A. The dot says that the role names (the two cs) are owned properties of the opposite side class.
There is no need to denote any aggregation if not required. If, and only if, use a composite aggregation which binds objects strong (that is, they die when all their compositors are dead). Don't use shared aggregation since it has an open semantic which needs to be defined in the domain before use.
That is what the shared AggregationKind is for (aka Aggregation).
You draw that as an association with a open diamond at the whole end.
If the Part class must always be part of both a Whole1 instance as a Whole2 instance, you can indicate that with the multiplicity 1

Is this an invalid object diagram, and what is association inheritance?

I have one class diagram and one object diagram. Is the object diagram valid according to the given class diagram?
Can I say it is invalid because :C has no alpha link with any S type object?
Or it is valid because :C and :T have already an alpha link if they have a beta link because C and T are subclasses of the A and S classes respectively?
The instance specifications are invalid (or at least incomplete) because the instance of C has no alpha link to the instance of T.
However, if you were to draw a generalization relationship between the beta and alpha associations, that would make the instance specifications valid as they stand. A generalization between the associations would imply the unnamed end of type T is a subset of values for the unnamed end of type S. §11.5.3.1 (Associations) in the UML 2.5 spec says, "specialization means that a link classified by the specializing Association is also classified by the specialized Association."
BTW, please always name the ends of your associations. This answer would have been easier to express if I could have mentioned the association ends by name. Having names for these also reduces confusion when communicating with other people on a team.

UML Circular reference with both aggregation and composition

A few days ago a friend pointed out to me that I had a wrong idea of composition in UML. She was completely right, so I decided to find out what more I could have been wrong about. Right now, there is one more thing that I have doubts about: I have a circular dependency in my codebase that I would like to present in UML form. But how.
In my case the following is true:
Both A and B have a list of C
C has a reference to both A and B to get information from.
C cannot exist if either A or B stops to exist
Both A and B remain to exist after C is deleted from A and/or B
To model this, I've come up with the following UML (I've ommited multiplicities for now, to not crowd the diagram.)
My question is, is this the right way to model such relations?
Problems
Some facts to keep in mind:
Default multiplicity makes your model invalid. A class may only be composed in one other class. When you don't specify multiplicity, you get [1..1]. That default is sad, but true.
The UML spec doesn't define what open-diamond aggregation means.
Your model has many duplicate properties. There is no need for any of the properties in the attribute compartments, as there are already unnamed properties at the ends of every association.
Corrections
Here is a reworking of your model to make it more correct:
Notice the following:
The exclusive-or constraint between the associations means only one of them can exist at a time.
Unfortunately, the multiplicities allow an instance of C to exist without being composed by A or B. (See the reworked model below.)
The property names at the ends of all associations explicitly name what were unnamed in your model. (I also attempted to indicate purpose in the property names.)
The navigability arrows prevent multiple unwanted properties without resorting to duplicative attributes.
Suggested Design
If I correctly understand what your model means, here is how I would probably reverse the implementation into design:
Notice the following:
Class D is abstract (the class name is in italics), meaning it can have no direct instances.
The generalization set says:
An instance cannot be multiply classified by A and B. (I.e., A and B are {disjoint}.)
An instance of D must be an instance of one of the subclasses. (I.e., A and B are {complete}, which is known as a covering axiom.)
The subclasses inherit the ownedC property from class D.
The composing class can now have a multiplicity of [1..1], which no longer allows an instance of C to exist without being composed by an A or a B.
Leave away the open diamonds and make them normal associations. These are no shared aggregations but simple associations. The composite aggregations are ok.
In general there is not much added value in showing aggregations at all. The semantic added value is very low. In the past this was a good hint to help the garbage collection dealing with unneeded objects. But nowadays almost all target languages have built-in efficient garbage collectors. Only in cases where you want an explicit deletion of the aggregated objects you should use the composite aggregation.

UML Class diagram object composed of 4 objects of another class?

I have one object, call it type A which has four data members of another object type, call it B. How do I show this in a UML class diagram so that its clear there are four B objects type in every A object?
Is the only solution to put "4" next to the arrow head pointing to class B?
It depends on what you want to achive, in sense of how you need to distinguish between those objects in context of their association/link, that is - what kind of role they play:
if there are all equal, no special differences in their role in context of A, them a multiplicity 4..4 will do the job, naming the association end properly (for example my_Bs)
If these object play different role in connection with A, then you can use separate associations with lower multiplicities each one, 2, 3 or even 4 pieces (for example, if B is a Wheel and A is Car, then you can put 2 associations with multiplicities 2..2 each, and call then "front" and "rear", or even 4 associations "front_left", "front_right"...)
Here is how the both cases look like. On the second one I showd different possible options (with max. 5 elements of B), just to give you an idea.
It's probably clear by now, but the fundamental concept here is the role of the association end.
Aleks answer is the best. However you can also represent the multiplicity in one box like this :
You cal also use composite structure diagram. See example below:
From my point of view, myBs defined as an attribute of type B on class A has a different meaning of myBs defined as a association's role between A and B (which is also different as defining it as a composition/aggregation).
If it is an attribute, then it's not a role. In that case, there is only a simple dependency relation between A and B, which must appear in the diagram.
I think that problem comes from unconsciously think from a "Relationnal Data (BMS)" and/or a "Object Oriented Programming" point of view, but UML is not intended for that.
:)

property owned by an association vs. property owned by a class?

What is the differences between property owned by an association and a property owned by a class in UML?
is there a simple example helps me understand the differences?
The difference is more conceptual than anything else. If you have a property attached to an association, then you will have an association class, with the desired property.
Here is an example of a mailman sending letters to clients (the attribute weight is bound to the association):
The difference is very concrete, but traditionally ignored.
A is associated to B. A,B are classes.
If B end of the association is "association owned" and navigable, it means, that you can easily reach instance of B from A, either by reference, or by some method(s). It should be shown by arrow.
If B end is "classifier owned", you know a bit more. it means, that A has an attribute, that is a direct reference. (No functions or reference counting here). It should be shown by arrow and "dot"- a small black filled circle.
If you are going to B by a.smth.smthelse.b, it is arrow, but surely no dot.
If you are going to B by a.b, it is arrow and dot.
If you haven't decided yet, it is arrow again.
Traditionally modellers show arrows only. But it is not a good tradition, and is against UML standard. Diagrams are more useful if we decide as much as possible on them, not in code.
If both ends are navigable, both arrows disappear and you may see only dot(s).
The association lines with cross with dot on one side, or arrow on one side and only dot on the other are senseless.

Resources