lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

index.md (6020B)


      1 +++
      2 title = 'Structure modeling with UML'
      3 +++
      4 ## Structure modeling with UML
      5 
      6 ### Class
      7 
      8 a construction plan for a set of similar objects of a system
      9 
     10 ![UML Class Diagram](uml-class.png)
     11 
     12 #### Attribute syntax
     13 
     14 ![UML Attribute Syntax](uml-attribute-syntax.png)
     15 
     16 Visibility: who is permitted to access the attribute
     17 * `+` public, everybody
     18 * `-` private, only the object itself
     19 * `#` protected, class itself and subclasses
     20 * `~` package, classes that are in the same package
     21 
     22 `/` means that attribute value is derived from other attributes
     23 
     24 Type:
     25 * primitive data type
     26     * pre-defined: Boolean, Integer, UnlimitedNatural, String
     27     * User-defined: «primitive»
     28     * composite: «datatype»
     29 * enumerations: «enumeration»
     30 
     31 ![UML Data Types](uml-data-types.png)
     32 
     33 Multiplicity: number of values an attribute may contain (as [min..max], max can be `*` meaning no limit)
     34 
     35 `= Default`: the default value that's used if the user doesn't explicitly set a value
     36 
     37 properties:
     38 * `[readOnly]` - value can't be changed
     39 * `[unique]` - no duplicates allowed
     40 * `[non-unique]` - duplicates allowed
     41 * `[ordered]` - fixed order of values
     42 * `[unordered]` - no fixed order of values
     43 
     44 #### Operation syntax
     45 
     46 ![UML operation syntax](uml-operation-syntax.png)
     47 
     48 Similar to attributes.
     49 
     50 parameter:
     51 * direction
     52     * `in`: input parameter (value is expected)
     53     * `out`: output parameter (adopts a new value after execution of operation)
     54     * `inout`: combined input/output
     55 
     56 ![UML operation parameter notation](uml-operation-parameter-notation.png)
     57 
     58 type: type of return value
     59 
     60 #### Class variable and class operation
     61 Class variable (static): defined only once per class, shared by all instances
     62 
     63 Class operation (static): can be used without creating an instance
     64 
     65 To distinguish class variables/operations, underline them.
     66 
     67 ### Relationships
     68 
     69 #### Binary association
     70 Connects instances of two classes with one another.
     71 
     72 ![UML Class Binary association](uml-class-binary-association.png)
     73 
     74 Properties:
     75 * Navigability: an object knows its partner objects, can access their visible attributes and operations (open arrow head, if not then cross). If undefined, bidirectional is assumed.
     76 * Multiplicity: number of objects that can be associated with exactly one object of the opposite side (e.g. one-to-one, one-to-many...)
     77 * Role: how an object is involved in an association relationship
     78 * `xor` constraint: cannot be associated with both at the same time
     79 
     80 in Java:
     81 
     82 ```java
     83 class Professor {...}
     84 
     85 class Student {
     86     public Professor[] lecturer;
     87 }
     88 ```
     89 
     90 #### n-ary association
     91 More than two objects involved in the relationship, no navigation directions.
     92 
     93 ![UML Class Ternary Association](uml-class-ternary-association.png)
     94 
     95 #### Association class
     96 Assign attributes to relationship between classes instead of to a class.
     97 
     98 ![UML Class Association class](uml-class-association-class.png)
     99 
    100 Needed for n:m associations.
    101 
    102 Association class vs regular class:
    103 
    104 ![UML Class Association vs regular](uml-class-association-vs-regular.png)
    105 
    106 Can be unique or non-unique.
    107 
    108 #### Aggregation
    109 Shows that class is part of another class.
    110 
    111 Properties:
    112 * transitive: if B is part of A and C is part of B, C is also part of A
    113 * asymmetric: not possible for A to be part of B and B to be part of A at the same time
    114 
    115 ##### Shared aggregation
    116 expresses weak belonging of the parts to a whole (parts also exist independently of the whole). one element can be part of multiple other elements at the same time.
    117 
    118 Example:
    119 
    120 ![UML Class shared aggregation example](uml-class-shared-aggregation-example.png)
    121 
    122 ##### Composition
    123 existence dependency between composite object and its parts. one part can be contained in max one composite object at a point in time. if the composite object is deleted, so are its parts.
    124 
    125 A `Tire` can exist without a `Car`. A `Tire` belongs to max one `Car`:
    126 
    127 ![UML Class composition example](uml-class-composition-example.png)
    128 
    129 #### Generalization
    130 stuff from a superclass is passed to its subclass (attributes, operations, associations, aggregations)
    131 
    132 every instance of a subclass is simultaneously an indirect instance of the superclass. subclass inherits all characteristics except private ones. generalizations are transitive. a class may have multiple superclasses/subclasses.
    133 
    134 ![UML Class generalisation](uml-class-generalisation.png)
    135 
    136 abstract class ensures that there are no direct instances of the superclass.
    137 
    138 ![UML Class abstract](uml-class-abstract.png)
    139 
    140 ### Creating a class diagram
    141 nouns often indicate classes. adjectives indicate attribute values. verbs indicate operations.
    142 
    143 in general, tend towards having deep classes. push complexity as low as possible in the class diagram hierarchy.
    144 
    145 focus on:
    146 * responsibility of each class (private is default, `getter` and `setter` methods)
    147 * knowledge needed by each class (tend toward generality, don't focus on order of tasks)
    148 * usability of operations of each class (exposed APIs should be as easy and intuitive as possible
    149 
    150 generalization: "there is difference between research and administrative employees. some research associates hold courses, so they are lecturers."
    151 
    152 ![UML Natural text generalization](uml-natural-text-generalization.png)
    153 
    154 composition: "a university consists of multiple faculties which are composed of various institutes."
    155 
    156 ![UML Natural text composition](uml-natural-text-composition.png)
    157 
    158 binary association: "each faculty is led by a dean, who is an employee of the university"
    159 
    160 ![UML Natural text binary association](uml-natural-text-binary-association.png)
    161 
    162 shared aggregation: "research associates are assigned to at least one institute"
    163 
    164 ![UML Natural text shared aggregation](uml-natural-text-shared-aggregation.png)
    165 
    166 association class: "research associates can be involved in projects for a certain number of hours"
    167 
    168 ![UML Natural text association class](uml-natural-text-association-class.png)
    169 
    170 generalization: "some research associates hold courses. then they are called lecturers."
    171 
    172 ![UML Natural text inheritance](uml-natural-text-inheritance.png)
    173