Week 2 Flashcards
What do class diagrams do?
They support the specification of the structure of systems by describing elements of the system and relations between them.
Objects in Class Diagrams (Representation)
An object is represented by a rectangle divided by a line. Above the line there is, e.g., HelenLewis:Student, where HelenLewis is the name of the object and Student is the class. Below the line are all of the different attributes of the object, e.g., firstName = “Helen”, secondName = “Lewis”, etc.
- the representation shows only a snapshot of the object at a specific point in time
How are relationships between two objects/classes represented?
A solid line
Classes (Representation in Class Diagrams)
Similar to objects, rectangle divided in THREE compartments.
First compartment has class name, second all of the variables, and the third the operation
Attributes and Operations in Class Diagrams
Have at least a name, e.g., hours and getLecturer().
Can also have their type specified, e.g.,
hours: float and getLecturer():Lecturer
Default values can be set as follows:
hours:float = 20
hours:float {readOnly} means that the attribute’s value cannot be changed
forward slash before attribute name indicates that its value is derived from other attributes, e.g., /credits:int
optional visibility marker (+,-,#,~) denotes whether an attribute is public, private, protected, or package, respectively; e.g.,
+hours: int
multiplicity of an attribute indicates how many values it can contain (helpful to define arrays, lists, sets, etc.); e.g., hours:float [min … max]
- * can also be used to specify that there is no upper limit
- sets, multi-set, ordered sets and lists can be created by combining one of the two properties {unique}, {non-unique} and one of the two properties {ordered}, {unordered}
- the former specifies whether duplicates are allowed whilst the latter specifies whether the elements are ordered or not
static/class operations and attributes are underlined
for operations, the operation name may be followed by a list of parameters in parentheses, e.g., getName(out fn: String, out ln: String): void
- before the parameter value you add out, in or inout:
1. Out: new value for parameter after operation execution
2. In: parameter value used for operation
3. Inout: parameter value used for operation and adopts new value after execution
Private, Public, Protected, Package
- only an object itself knows the values of attributes marked as private
- anyone can view attributes marked as public
- access to protected attributes is reserved for a class itself and its subclasses
- if a class has a package attribute, only classes that are in the same package as this class may access this attribute
Binary Associations
show an association between the isntances of two classes with one another
represented by solid line
can be labelled with the name of the association and optionally the reading direction
Navigability of Binary Associations
indicates thatn an object knows its partner object and can therefore access their visible attributes and operations
an arrowhead indicates navigability, whilst an X indicates non-navigability
no arrowhead/X on either side indicates bidirectional navigability
Multiplicity of Associations
specify the number of objects that may be associated with exactly one object of the opposite side
also given in the form minimum…maximum or *
role names can be added to specify the role of a given object/class in an association
XOR Association
link the base class to both of the possible classes with solid lines, and then draw two dashed lines from each of those lines with an {xor} where they meet
N-ary association
involves more than two partner objects
has no navigation directions
Association Class
used to assign attributes to a relationship between classes rather than to a class itself
necessary when modelling n:m associations
dashed line from solid association line and a new class connected to that dashed line
usually, there can only be one of these classes for a given association, but this can be changed by specifying {non-unique} next to the class
Aggregation
special form of association used to express that a class is part of another class
Shared Aggregation
expresses a weak belonging of the parts to a whole, i.e., the parts also exist independently of the whole
e.g., Student is part of LabClass
multiplicity at the aggregating end may be >1 (i.e., the student may be part of multiple lab classes)
represented by an open rhombus
spans a directed acyclic graph
Generalisation
all characteristics, associations, and aggregations specified for the superclass are passed onto its subclass
every instance of the subclass is indirect instance of superclass
subclass may have further characteristics, associations and aggregations
transitive
Composition
existence dependency between the composite object and its parts
multiplicty at the aggregating end is max 1, i.e., the part can only be part of one whole
represented by a filled-in rhombus
spans a tree
if the composite object is deleted, so are its parts