Software Engineering System Modeling Extra examples Dr.Doaa Sami Modified from Sommerville’s originals
2 C. Structural Models
3 1. C l a s s D i a g r a m
attribute values +getlength(): double Class Attributes 7 Visibility name : type [count] = default_value underline static attributes. Student Visibility -name: string + public - totalStudent:int # protected + getName(): string - private + getTotalStuden()t:int / derived derived attribute: not stored, -length: double -width:double attribute values +getlength(): double +getArea(): double - salary: double + getSalary(): double Rectangle /area:double but can be computed from other +getWidth():double
Visibility -name: string Class Operations 8 Visibility name (parameters) : return_type underline static operations. Student Visibility -name: string + public - totalStudent:int # protected + getName(): string - private + getTotalStuden()t:int return_type is omitted if function is: Rectangle constructor -length: double void -width:double +getlength(): double +getWidth():double +getArea():double - salary: double + getSalary(): double /area:double
Relationships 9 There are two kinds of Relationships Association (student enrolls in course). Generalization (parent-child relationship). Associations can be further classified as Aggregation. Composition.
Association Associations denote relationships between classes. 10 Associations denote relationships between classes. Describe the nature of the relationship. Example: Student enrolls into course Course enrolled by a student. Student Course Enrolls
Multiplicity relates to ONE instance of another class. 11 Multiplicity is the number of instances one class relates to ONE instance of another class. For each association, there are two multiplicity decisions to make, one for each end of the association. For each instance of Professor, many Sections may be taught. For each instance of Section, there may be either one or zero Professor as the instructor. Professor Section -name:string 0..1 has 0..* -section#:int +getName():string +getSection#:int
Multiplicity (C++ Implementation) 12 Professor Section -name:string 0..1 has 0..* -section#:int +getName():string +getSection#:int class Professor{ class Section{ // A list of Sections // Proffessor Section sec[4]; Professor prof; string name; int sectionNum; Public: Public: string getName(); int getSectionNum(); }; } ;
Multiplicity Representation 13
Aggregation models a whole-part relationship between an 14 Association is used when both of the involved classes are equaly important. Aggregation is a special form of association that models a whole-part relationship between an aggregate (the whole) and its parts. Aggregation shows how classes that are collections are composed of other classes. Aggregation is a part-of relationship. Car 1 4 Wheel
Composition 15 Composition is a strong form of aggregation. Aggregation is used to model a whole-part relationship between an aggregate (whole) and its parts. Composition is a strong form of aggregation. The whole is the only owner of its part. Multiplicity on the whole side must be one. The lifetime of the part is dependent upon the whole. When Circle is destroyed, Point is also destroyed. The composite must manage the creation and destruction of its parts.
Composition (C++ Implementation) 16 Restaurant 1 1 Menu class Restaurant{ class Menu{ .... }; Menu m; }; ....
Generalization Cows and Wolfs are Mammals. 17 Rather than learn the detailed characteristics of every entity that we experience, we place these entities in more general classes (animals, cars, houses, etc.) and learn characteristics of these classes. This allows us to infer that different members of these classes have some common characteristics e.g. Cows and Wolfs are Mammals.
Generalization Cont. 18 In object-oriented languages, generalization is implemented using class inheritance mechanisms. In a generalization, the attributes and operations associated with higher-level classes (super classes) are also associated with the lower-level classes (sub classes). Subclasses are inherit the attributes and operations from their Superclasses and then add more specific attributes and operations.
Generalization 19
Association Class association connection to have operations and 20 An association class is a construct that allows an association connection to have operations and attributes. It used when you need to include another class because it includes valuable information about the relationship.
Example: Information System for School 21