1.51k likes | 1.66k Views
University of Palestine Faculty of Engineering and Urban planning Software Engineering Department. Software Modeling SWE5441. Lecture 4. Eng. Mohammed Timraz Electronics & Communication Engineer. Outlines. Introduction Static/structural diagram Class diagrams Object diagrams
E N D
University of Palestine • Faculty of Engineering and Urban planning • Software Engineering Department Software ModelingSWE5441 Lecture 4 Eng. Mohammed Timraz Electronics & Communication Engineer
Outlines • Introduction • Static/structural diagram • Class diagrams • Object diagrams • Package diagrams • Component diagrams • Dynamic/behavioral diagram types • Sequence diagrams • Activity diagrams • A data flow diagram UML Diagrams
Modeling • A way of thinking about the problems using models organized around the real world ideas. • A modeling method comprises a language and also a procedure for using the language to construct models. • Visualize your design and check it against requirements before your crew starts to code. • A Diagram is the graphical presentation of a set of elements, most often rendered as a connected graph of things and relationships. UML Diagrams
Unified Modeling Language (UML) • Not simply a notation for drawing diagrams, but a complete language for capturing knowledge about a subject and expressing knowledge regarding the subject for the purpose of communication. • It is the result of unifying the information systems and technology industry’s best engineering practices (principals, techniques, methods and tools). UML Diagrams
UML Diagrams • UML diagrams represent two different views of a system model: • Static /Structure diagrams • Dynamic / Behavior diagrams UML Diagrams
Static /Structure diagrams • Structure diagrams shows: • The static structure of the system and it's parts on different abstraction and implementation levels. • How they are related to each other. • The elements in a structure diagram represent the meaningful concepts of a system, and may include abstract, real world and implementation concepts. UML Diagrams
Static /Structure diagrams • Class diagrams, • Object diagrams, • Package diagrams, • Component diagrams. UML Diagrams
Class Diagram UML Diagrams
Class Diagram • What is a Class Diagram? • Essential Elements of a UML Class Diagram. • Relationships in class Diagrams. • Class Diagrams Case Study UML Diagrams
What is a Class Diagram? • Class diagrams are the backbone of object oriented analysis and design. • A central modeling technique that runs through nearly all object-oriented methods. • The richest notation in UML. • Class diagrams show: • The classes of the system, • Their inter relationships (including inheritance, aggregation, and association), • The operations and attributes of the classes. UML Diagrams
Essential Elements of a UML Class Diagram • Class, • Attributes, • Operations, • Relationships: • Associations, • Generalization, • Dependency, • Realization, • Constraint Rules and Notes. UML Diagrams
Window size: Sizevisibility: Boolean display()hide() Classes • A class is the description of a set of objects having similar: • Attributes, • Operations, • Relationships, • Behavior. Class Name Attributes Operations UML Diagrams
Relationships Descriptions: • Associations, • Generalization, • Dependency, • Realization, UML Diagrams
Associations • A semantic relationship between two or more classes that specifies connections among their instances. • A structural relationship, specifying that objects of one class are connected to objects of a second (possibly the same) class. UML Diagrams
Association Name Association Works for University Professor Associations Examples • Association shows more significant link between two rows of objects representing a straight line connecting between the grades. • The following example illustrates the working relationship between the university and the professor because the teacher works at the University of UML Diagrams
Association Name Association Manages of Manager Department managed manager Role Names Class Associations Examples The following example illustrates the relationship runs between the Director and the Director of the section because each section runs. UML Diagrams
Factory Product creates Associations Examples Parental relationship between father and son Relationship between plant production and product UML Diagrams
Associations Role name Association name instructor Staff Member Student 1..* instructs * Role Navigable (uni-directional) association Multiplicity * pre - requisites Courses 0..3 Reflexive association UML Diagrams
Associations • To clarify its meaning, an association may be named. • The name is represented as a label placed midway along the association line. • Usually a verb or a verb phrase. Association name Staff Member Student instructs UML Diagrams
Associations • A role is an end of an association where it connects to a class. • May be named to indicate the role played by the class attached to the end of the association path. • Usually a noun or noun phrase. • Mandatory for reflexive associations. Rolename Association name instructor Staff Member Student instructs UML Diagrams
Associations • Multiplicity • The number of instances of the class, next to which the multiplicity expression appears, that are referenced by a single instance of the class that is at the other end of the association path. Role name Association name instructor Staff Member Student 1..* instructs * Multiplicity UML Diagrams
Associations • Multiplicity Indicators: UML Diagrams
2..* 1..* Door Car House Aggregation • A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts. • Models a “is a part-part of” relationship. Whole Whole Part UML Diagrams
2..* Door Car Aggregation • Aggregation tests: • Is the phrase “part of” used to describe the relationship? • A door is “part of” a car • Are some operations on the whole automatically applied to its parts? • Move the car, move the door. • Are some attribute values propagated from the whole to all or some of its parts? • The car is blue, therefore the door is blue. • Is there an intrinsic asymmetry to the relationship where one class is subordinate to the other? • A door is part of a car. A car is not part of a door. Whole Part UML Diagrams
Whole Part Student Schedule Composition Composition • A strong form of aggregation • The whole is the sole owner of its part. • The part object may belong to only one whole • Multiplicity on the whole side must be zero or one. • The life time of the part is dependent upon the whole. • The composite must manage the creation and destruction of its parts. UML Diagrams
Bank Account Transactions Customer Info Composition • Example: Part Whole Part UML Diagrams
An abstract class Shape{abstract} Super Class Generalization relationship Sub Class Circle Generalization • Indicates that objects of the specialized class (subclass) are substitutable for objects of the generalized class (super-class). • “is kind of” relationship. {abstract} is a tagged value that indicates that the class is abstract. The name of an abstract class should be italicized UML Diagrams
Generalization • A sub-class inherits from its super-class • Attributes • Operations • Relationships • A sub-class may • Add attributes and operations • Add relationships • Refine (override) inherited operations • Note: A generalization relationship may not be used to model interface implementation. UML Diagrams
Dependency • A dependency indicates a semantic relation between two or more classes in which a change in one may force changes in the other although there is no explicit association between them. • A stereotype may be used to denote the type of the dependency. Iterator <<friend>> Vector UML Diagrams
Dependency • In an e-commerce application, a Cart class depends on a Product class because the Cart class uses the Product class as a parameter for an add operation. This relationship indicates that a change to the Product class might require a change to the Cart class. Thedependent class Dependency Relationship Theindependent class Cart Product add(Product p) UML Diagrams
Realization • A realization relationship indicates that one class implements a behavior specified by another class (an interface or protocol). • An interface can be realized by many classes. • A class may realize many interfaces. LinkedList <<interface>>List LinkedList List UML Diagrams
id: long { value > 0 } Customer 1 * Order may be canceled { total < $50 } Constraint Rules and Notes • Constraints and notes annotate among other things associations, attributes, operations and classes. • Constraints are semantic restrictions noted as Boolean expressions. • UML offers many pre-defined constraints. Constraint Note UML Diagrams
TrafficReport Offender 1 issues * TrafficPoliceman 1..* 1 id : long name : String description : String id : long occuredAt : Date reports of 1..* Policeman Violation id : long name : String id : long rank : int description : String <<abstract>> TVRS – Traffic Violation Report System Example: UML Diagrams
Case Study: • Draw a class diagram for a information modeling system for a school. • School has one or more Departments. • Department offers one or more Subjects. • A particular subject will be offered by only one department. • Department has instructors and instructors can work for one or more departments. • Student can enrol in upto 5 subjects in a School. • Instructors can teach upto 3 subjects. • The same subject can be taught by different instructors. • Students can be enrolled in more than one school. UML Diagrams
Case Study: School has one or more Departments. School Department has 1..* 1 Department Subject offers 1..* 1 • Department offers one or more Subjects. • A particular subject will be offered by only one department. UML Diagrams
Case Study: Department has Instructors and instructors can work for one or more departments. Instructor Department 1..* assigned to 1..* Student Subject takes 0..5 * • Student can enrol in upto 5 Subjects. UML Diagrams
Case Study: Instructors can teach up to 3 subjects. The same subject can be taught by different instructors. 1..* Instructor Subjects 1..3 teaches UML Diagrams
Case Study: Students can be enrolled in more than one school. * Student School 1..* member UML Diagrams
Department Instructor Subject Student School Case Study: Final Class Diagram has 1 1..* 1..* 1…* 1 offeres assignedTo member 1..* 1..* * attends teaches * 1..5 1..* 1..3 UML Diagrams
Object Diagram • Object Diagram shows the relationship between objects. • Unlike classes objects have a state. UML Diagrams
Object Diagrams • Models a set of objects and their interrelationships during a system snapshot. • A system snapshot is the state of the software system at a selected moment of time. • Object diagrams model another static perspective of the system. • Unlike other diagrams, object diagrams may contain multiple instances of the same class. UML Diagrams
LMS Case Study: Object Diagram (partial) :Book currentP: Student : List name = “SOTY”author=“b. hooks”ISBN= ... name=“Gert Stein”libraryID=6747632homephone=5554321workphone=5551234membership=05011999expire=05012002 :Book name = “FOF”author=“Ehrenreich”ISBN= ... UML Diagrams
Steps for Creating Object Diagrams • Identify a system snapshot within a scenario to model. • Identify participating classes and their interrelationships. • Identify all allocated objects at the time of the snapshot. • Show the state of each object in the snapshot. • Determine all inter-object links. UML Diagrams
c1: Company name=“UniMelb” Object Diagram - Example c1: Company d1: Department d2: Department name=“Sales” name=”CSSE” manager employee p2: Person p1: Persont name=“Raj” name=“Rao” UML Diagrams
Class Vs. Object Diagrams Class Name Association Name Customer Rental Item Rents +id:integer +id:integer 0..n +name:string +released:date 0..1 Class Diagram Attributes Object Name Link Name Aly: Customer UML: Rental Item Rents +id:1667 +id:22340 +name: Aly ahmed +released:1942 Object Diagram UML Diagrams
Class and Object Diagrams 2 Class Vs. Object Diagrams UML Diagrams
Name UML Packages • A package is a general purpose grouping mechanism. • Can be used to group any UML element (e.g. use case, actors, classes, components and other packages. • Commonly used for specifying the logical distribution of classes. • A package does not necessarily translate into a physical sub-system. UML Diagrams
Logical Distribution of Classes • Emphasize the logical structure of the system (High level view) • Higher level of abstraction over classes. • Aids in administration and coordination of the development process. • Contributes to the scalability of the system. • Logical distribution of classes is inferred from the logical architecture of the system. UML Diagrams
A D E F G C B Packages and Class Diagrams • Add package information to class diagrams UML Diagrams