3.2.5. Associations: The Relations Is - A and Has - A Are Fundamental Ways To Understand Collections of Classes
3.2.5. Associations: The Relations Is - A and Has - A Are Fundamental Ways To Understand Collections of Classes
3.2.5. Associations: The Relations Is - A and Has - A Are Fundamental Ways To Understand Collections of Classes
Associations
The relations is_a and has_a are fundamental
ways to understand collections of classes.
role names
For example …
subject
Student Course
participant
name title
marries
Priests
John Smith
760901-1234
Mary Jones
691205-5678
People Tax_codes
• One-to-many
mother_of
M.E. Meinke
K. Meinke
N. Meinke
Women
People
• Many-to-many
parent_of
M.E. Meinke
K. Meinke
K.W. Meinke
N. Meinke
People People
Relation R between classes X and Y is:
one-to-many
1 *
Class_A Class_B
many-to-many
* *
Class_A Class_B
1 *
Class_A Class_B
We can express a choice of multiplicities
in other ways, e.g
• 1, 3, 5 1 or 3 or 5
• 7, 9 .. 12 7 or 9 or 10 or 11 or 12
3.3. Mapping to Code
MyPackage package MyPackage
abstract class
MyAbstractClass
MyAbstractClass
package MyPackage
class MyDerivedClass
extends MyAbstractClass
MyDerivedClass {
att: int int att;
void myFunction(
myFunction() referencedClass r ) { .. }
}
Aggregation
MyAggregatedClass }
Dependence
3 possible implementations!
class MyDependentClass
MyClass {
void myFunction1(
att: int
MyReferencedClass r ) { .. }
myFunction()
MyreferencedClass
dependence myFunction2( .. ) { .. }
arrow
• object name,
• object type (class),
• attribute names,
• attribute values.
For example …
typeless
name name :
type
: type name :
type
attribute = value
anonymous
3.3.2. Links
A link is a concrete instance of an association
or relation.
l = ( o1 , …, on ) R
has
Biplane Wing
2
Upper_wing :
has Wing
Sopwith-Camel :
Biplane
has
Lower_wing :
Wing
But this object diagram is not a valid instance
of the previous class diagram:
Object_1 : Object_2 :
Class_1 Class_2
Object_3 :
Class_3
Object composition and aggregation use the
same symbols as for classes, e.g.
Component1 : Component2 :
Class_1 Class_2
Object :
Class
Notice that now we can capture the semantic
difference between composition and
aggregation. E.g. the following is illegal
P1 : Polygon L1 : Line
!!!!!
Start : Point Myname : Name
x=0 text = “big”
y=0
We can use object diagrams to understand
recursively defined classes. For example,
the class diagram
Binary_Tree
0,1
0 .. 2
has the object diagram
T1 : Binary
Tree
T2 : Binary T3 : Binary
Tree Tree
T4 : Binary T5 : Binary
Tree Tree
4. Software Architectures
Software architecture: structure or structures
of the system which comprise software
components, externally visible properties of
these components, and relationships among
them.