structure-modeling.html (9050B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script type="text/javascript" async src="https://cdn.jsdelivr.net/gh/mathjax/MathJax@2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> 5 <link rel="Stylesheet" type="text/css" href="style.css"> 6 <title>structure-modeling</title> 7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 8 </head> 9 <body> 10 11 <div id="Structure modeling with UML"><h2 id="Structure modeling with UML">Structure modeling with UML</h2></div> 12 13 <div id="Structure modeling with UML-Class"><h3 id="Class">Class</h3></div> 14 15 <p> 16 a construction plan for a set of similar objects of a system 17 </p> 18 19 <p> 20 <img src="img/uml-class.png" alt="UML Class Diagram" /> 21 </p> 22 23 <div id="Structure modeling with UML-Class-Attribute syntax"><h4 id="Attribute syntax">Attribute syntax</h4></div> 24 25 <p> 26 <img src="img/uml-attribute-syntax.png" alt="UML Attribute Syntax" /> 27 </p> 28 29 <p> 30 Visibility: who is permitted to access the attribute 31 </p> 32 <ul> 33 <li> 34 <code>+</code> public, everybody 35 36 <li> 37 <code>-</code> private, only the object itself 38 39 <li> 40 <code>#</code> protected, class itself and subclasses 41 42 <li> 43 <code>~</code> package, classes that are in the same package 44 45 </ul> 46 47 <p> 48 <code>/</code> means that attribute value is derived from other attributes 49 </p> 50 51 <p> 52 Type: 53 </p> 54 <ul> 55 <li> 56 primitive data type 57 58 <ul> 59 <li> 60 pre-defined: Boolean, Integer, UnlimitedNatural, String 61 62 <li> 63 User-defined: «primitive» 64 65 <li> 66 composite: «datatype» 67 68 </ul> 69 <li> 70 enumerations: «enumeration» 71 72 </ul> 73 <blockquote> 74 <img src="img/uml-data-types.png" alt="UML Data Types" /> 75 </blockquote> 76 77 <p> 78 Multiplicity: number of values an attribute may contain (as [min..max], max can be <code>*</code> meaning no limit) 79 </p> 80 81 <p> 82 <code>= Default</code>: the default value that's used if the user doesn't explicitly set a value 83 </p> 84 85 <p> 86 properties: 87 </p> 88 <ul> 89 <li> 90 <code>[readOnly]</code> - value can't be changed 91 92 <li> 93 <code>[unique]</code> - no duplicates allowed 94 95 <li> 96 <code>[non-unique]</code> - duplicates allowed 97 98 <li> 99 <code>[ordered]</code> - fixed order of values 100 101 <li> 102 <code>[unordered]</code> - no fixed order of values 103 104 </ul> 105 106 <div id="Structure modeling with UML-Class-Operation syntax"><h4 id="Operation syntax">Operation syntax</h4></div> 107 108 <p> 109 <img src="img/uml-operation-syntax.png" alt="UML operation syntax" /> 110 </p> 111 112 <p> 113 Similar to attributes. 114 </p> 115 116 <p> 117 parameter: 118 </p> 119 <ul> 120 <li> 121 direction 122 123 <ul> 124 <li> 125 <code>in</code>: input parameter (value is expected) 126 127 <li> 128 <code>out</code>: output parameter (adopts a new value after execution of operation) 129 130 <li> 131 <code>inout</code>: combined input/output 132 133 </ul> 134 </ul> 135 136 <p> 137 <img src="img/uml-operation-parameter-notation.png" alt="UML operation parameter notation" /> 138 </p> 139 140 <p> 141 type: type of return value 142 </p> 143 144 <div id="Structure modeling with UML-Class-Class variable and class operation"><h4 id="Class variable and class operation">Class variable and class operation</h4></div> 145 <p> 146 Class variable (static): defined only once per class, shared by all instances 147 </p> 148 149 <p> 150 Class operation (static): can be used without creating an instance 151 </p> 152 153 <p> 154 To distinguish class variables/operations, underline them. 155 </p> 156 157 <div id="Structure modeling with UML-Relationships"><h3 id="Relationships">Relationships</h3></div> 158 159 <div id="Structure modeling with UML-Relationships-Binary association"><h4 id="Binary association">Binary association</h4></div> 160 <p> 161 Connects instances of two classes with one another. 162 </p> 163 164 <p> 165 <img src="img/uml-class-binary-association.png" alt="UML Class Binary association" /> 166 </p> 167 168 <p> 169 Properties: 170 </p> 171 <ul> 172 <li> 173 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. 174 175 <li> 176 Multiplicity: number of objects that can be associated with exactly one object of the opposite side (e.g. one-to-one, one-to-many...) 177 178 <li> 179 Role: how an object is involved in an association relationship 180 181 <li> 182 <code>xor</code> constraint: cannot be associated with both at the same time 183 184 </ul> 185 186 <p> 187 in Java: 188 </p> 189 190 <pre> 191 class Professor {...} 192 193 class Student { 194 public Professor[] lecturer; 195 } 196 </pre> 197 198 <div id="Structure modeling with UML-Relationships-n-ary association"><h4 id="n-ary association">n-ary association</h4></div> 199 <p> 200 More than two objects involved in the relationship, no navigation directions. 201 </p> 202 203 <p> 204 <img src="img/uml-class-ternary-association.png" alt="UML Class Ternary Association" /> 205 </p> 206 207 <div id="Structure modeling with UML-Relationships-Association class"><h4 id="Association class">Association class</h4></div> 208 <p> 209 Assign attributes to relationship between classes instead of to a class. 210 </p> 211 212 <p> 213 <img src="img/uml-class-association-class.png" alt="UML Class Association class" /> 214 </p> 215 216 <p> 217 Needed for n:m associations. 218 </p> 219 220 <p> 221 Association class vs regular class: 222 </p> 223 224 <p> 225 <img src="img/uml-class-association-vs-regular.png" alt="UML Class Association vs regular" /> 226 </p> 227 228 <p> 229 Can be unique or non-unique. 230 </p> 231 232 <div id="Structure modeling with UML-Relationships-Aggregation"><h4 id="Aggregation">Aggregation</h4></div> 233 <p> 234 Shows that class is part of another class. 235 </p> 236 237 <p> 238 Properties: 239 </p> 240 <ul> 241 <li> 242 transitive: if B is part of A and C is part of B, C is also part of A 243 244 <li> 245 asymmetric: not possible for A to be part of B and B to be part of A at the same time 246 247 </ul> 248 249 <div id="Structure modeling with UML-Relationships-Aggregation-Shared aggregation"><h5 id="Shared aggregation">Shared aggregation</h5></div> 250 <p> 251 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. 252 </p> 253 254 <p> 255 Example: 256 </p> 257 258 <p> 259 <img src="img/uml-class-shared-aggregation-example.png" alt="UML Class shared aggregation example" /> 260 </p> 261 262 <div id="Structure modeling with UML-Relationships-Aggregation-Composition"><h5 id="Composition">Composition</h5></div> 263 <p> 264 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. 265 </p> 266 267 <p> 268 A <code>Tire</code> can exist without a <code>Car</code>. A <code>Tire</code> belongs to max one <code>Car</code>: 269 </p> 270 271 <p> 272 <img src="img/uml-class-composition-example.png" alt="UML Class composition example" /> 273 </p> 274 275 <div id="Structure modeling with UML-Relationships-Generalization"><h4 id="Generalization">Generalization</h4></div> 276 <p> 277 stuff from a superclass is passed to its subclass (attributes, operations, associations, aggregations) 278 </p> 279 280 <p> 281 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. 282 </p> 283 284 <p> 285 <img src="img/uml-class-generalisation.png" alt="UML Class generalisation" /> 286 </p> 287 288 <p> 289 abstract class ensures that there are no direct instances of the superclass. 290 </p> 291 292 <p> 293 <img src="img/uml-class-abstract.png" alt="UML Class abstract" /> 294 </p> 295 296 <div id="Structure modeling with UML-Creating a class diagram"><h3 id="Creating a class diagram">Creating a class diagram</h3></div> 297 <p> 298 nouns often indicate classes. adjectives indicate attribute values. verbs indicate operations. 299 </p> 300 301 <p> 302 in general, tend towards having deep classes. push complexity as low as possible in the class diagram hierarchy. 303 </p> 304 305 <p> 306 focus on: 307 </p> 308 <ul> 309 <li> 310 responsibility of each class (private is default, <code>getter</code> and <code>setter</code> methods) 311 312 <li> 313 knowledge needed by each class (tend toward generality, don't focus on order of tasks) 314 315 <li> 316 usability of operations of each class (exposed APIs should be as easy and intuitive as possible 317 318 </ul> 319 320 <p> 321 generalization: "there is difference between research and administrative employees. some research associates hold courses, so they are lecturers." 322 </p> 323 324 <p> 325 <img src="img/uml-natural-text-generalization.png" alt="UML Natural text generalization" /> 326 </p> 327 328 <p> 329 composition: "a university consists of multiple faculties which are composed of various institutes." 330 </p> 331 332 <p> 333 <img src="img/uml-natural-text-composition.png" alt="UML Natural text composition" /> 334 </p> 335 336 <p> 337 binary association: "each faculty is led by a dean, who is an employee of the university" 338 </p> 339 340 <p> 341 <img src="img/uml-natural-text-binary-association.png" alt="UML Natural text binary association" /> 342 </p> 343 344 <p> 345 shared aggregation: "research associates are assigned to at least one institute" 346 </p> 347 348 <p> 349 <img src="img/uml-natural-text-shared-aggregation.png" alt="UML Natural text shared aggregation" /> 350 </p> 351 352 <p> 353 association class: "research associates can be involved in projects for a certain number of hours" 354 </p> 355 356 <p> 357 <img src="img/uml-natural-text-association-class.png" alt="UML Natural text association class" /> 358 </p> 359 360 <p> 361 generalization: "some research associates hold courses. then they are called lecturers." 362 </p> 363 364 <p> 365 <img src="img/uml-natural-text-inheritance.png" alt="UML Natural text inheritance" /> 366 </p> 367 368 </body> 369 </html>