lectures.alex.balgavy.eu

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

structure-modeling.wiki (6320B)


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