Presentation is loading. Please wait.

Presentation is loading. Please wait.

UML Class Diagrams Sequence Diagrams CSE230 Dae-Kyoo Kim.

Similar presentations


Presentation on theme: "UML Class Diagrams Sequence Diagrams CSE230 Dae-Kyoo Kim."— Presentation transcript:

1 UML Class Diagrams Sequence Diagrams CSE230 Dae-Kyoo Kim

2 Agenda Class Diagrams Class Diagrams Symbology Symbology Basic Modeling Basic Modeling Intermediate Modeling Intermediate Modeling Sequence Diagrams Sequence Diagrams Symbology Symbology

3 Class Diagrams A class diagram shows: A class diagram shows: Classes Classes Attributes Attributes Methods Methods Interfaces Interfaces Collaborations Collaborations Relationships: Dependency, Generalization, Association Relationships: Dependency, Generalization, Association A class diagram is a STATIC view of system A class diagram is a STATIC view of system

4 Basic Class Diagrams Window size: Size visibility: boolean display() hide() Class Name Attributes Operations

5 Basic Class Diagrams +public #protected -private / derived $ static Visibility Attribute Name [Multiplicity]:Type = Initial Value Visibility Method Name (Parameter List) : Return-List Class Scope Variable Abstract > …

6 Attribute Example (Java implementation) public class Note { public String author = “unknown”; public String text; private static long total = 0;... } + author: String = “unknown” + text : String - total : long = 0 Note

7 Operation Example (Java implementation) Figure - size: Size - pos : Position + move(pos : Position) + getFigureCount() : long public class Figure { private Size size; private Position pos; private static long figureCount = 0; public void move(Position pos) {... } public static long getFigureCount() { return figureCount; }... }

8 Basic Class Diagrams Superclass Subclass Inheritance (Generalization) (is-a, kind-of) Class with parts Assembly Class Aggregation (Part-Of) Association (relationship) Class with parts Assembly Class Dependency Class A Class B name Interface Concrete Class Realization

9 Associations A semantic relationship between two or more classes that specifies connections among their instances 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 A structural relationship specifying that objects of one class are connected to objects of a second (possibly the same) class Example: “An Employee works for a Company” Example: “An Employee works for a Company”

10 Associations (cont.) An association between two classes indicates that objects at one end of an association “recognize” objects at the other end and may send messages to them An association between two classes indicates that objects at one end of an association “recognize” objects at the other end and may send messages to them Borrower Book 31 currBorrbk[]

11 Association (Java implementation) public class Borrower { Book bk[]; int numBooks; … public Borrower() { numBooks = 0; bk = new Book[3]; } // methods that update bk public void borrowBook( Book b ) { bk[numBooks] = b; numBooks++; b.setBorrower( this ); } public class Book { Borrower currBorr; public void setBorrower( Borrower bw ) { currBorr = bw; }

12 Aggregation A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts. 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. Models a “is a part-part of” relationship. Whole Part Car Wheel 4 wheels

13 Aggregation (Java implementation) public class Car { private Wheel wheels[];... // wheel objects are created externally and // passed to the constructor public Car( Wheel w1, Wheel w2, … ) { // we can check w1, w2, etc. for null // to make sure wheels exist wheels = new Wheel[4]; wheels[0] = w1; wheels[1] = w2; … }

14 Composition A strong form of aggregation A strong form of aggregation The whole is the sole owner of its part The whole is the sole owner of its part The part object may belong to only one whole The part object may belong to only one whole Multiplicity on the whole side must be one Multiplicity on the whole side must be one The life time of the part is dependent upon the whole The life time of the part is dependent upon the whole The composite must manage the creation and destruction of its parts The composite must manage the creation and destruction of its parts LinePoint 3..* 2 Polygon

15 Composition (C++ implementations) class Circle { public: Circle() : center(1,2) {} private: Point center; }; class Circle { public: Circle() : center(new Point(1,2)) {} ~Circle() { delete center; } private: Point* const center; };

16 Composition (Java implementations) public class Car { private Wheel wheels[];... public Car() { wheels = new Wheel[4]; // Wheels are created in Car … wheels[0] = new Wheel(); wheels[1] = new Wheel(); … }... }

17 Generalization Indicates that objects of the specialized class (subclass) are substitutable for objects of the generalized class (super-class) Indicates that objects of the specialized class (subclass) are substitutable for objects of the generalized class (super-class) “is kind of” relationship “is kind of” relationship Shape Circle Super Class Sub Class An abstract class Generalization relationship

18 Generalization A sub-class inherits from its super-class A sub-class inherits from its super-class Attributes Attributes Operations Operations Relationships Relationships A sub-class may A sub-class may Add attributes and operations Add attributes and operations Add relationships Add relationships Refine (override) inherited operations Refine (override) inherited operations

19 Generalization (Java implementation) public abstract class Shape { public abstract void draw();... } public class Circle extends Shape { public void draw() {... }... }

20 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 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 A stereotype may be used to denote the type of the dependency Parser getTransaction() uses Bank processTransactions ()

21 Dependency (Java implementation) public class Bank { … public void processTransactions() { // Parser p is a local variable … Parser p = new Parser(…); … p.getTransaction(); … } … }

22 Realization A realization relationship indicates that one class implements a behavior specified by another class (an interface or protocol). 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. An interface can be realized by many classes. A class may realize many interfaces. A class may realize many interfaces. LinkedList > List LinkedList List

23 Realization (Java implementation) public interface List { boolean add(Object o);... } public class LinkedList implements List { public boolean add(Object o) {... }... }

24 Basic Class Diagram (Example) Person Student Class takes Head Arm

25 Basic Class Diagram (Example) Person + name : String - ssn : String # birthday : Date / age : int +getName : String -calculateAge : int

26 Class Diagrams (Advanced) Cardinality (Multiplicity) 1 0..1 0..n 1..n * Student Class takes 0..n

27 Class Diagrams (Advanced) Important Stereotypes: > specify collection of operations to specify services > specify structure and behavior (not implementation) > specify discrete values > helper class created in detail design > ImageReader > Complex readImage writeImage Fundamental behavior Fundamental Attributes > Status Idle Working Error

28 Class Diagrams (Advanced) Simple Aggregation (object lifetime) Composite Aggregation (unique member) Can have self-relations: employee manages manager Exception handling: >

29 Class Diagrams (Advanced) Patron Book Checks Out Association Class

30 TVRS Example id : long name : String rank : int Policeman > TrafficPoliceman id : long description : String TrafficReport id : long description : String Violation name : String id : long Offender 1..*1 reports of 1..* issues1* occuredAt : Date

31 Class Diagrams (Advanced) StaffMemberStudent 1..**instructs instructor Association name Role name Multiplicity Navigable (uni-directional) association Courses pre - requisites 0..3 Reflexive association Role *

32 Class Diagram Hints Provide abstraction of problem domain Provide abstraction of problem domain Embodies small set of well-defined responsibilities Embodies small set of well-defined responsibilities Clear separation between specification and implementation Clear separation between specification and implementation Understandable and simple Understandable and simple Show only important properties Show only important properties

33 Class Hints Organize similar classes into packages Organize similar classes into packages Beware of cyclical generalization Beware of cyclical generalization Use associations where there are structural relationships Use associations where there are structural relationships Associations are NOT comm pipes!!!!!!! Associations are NOT comm pipes!!!!!!! Start with Analysis, then refine details Start with Analysis, then refine details

34 Sequence Diagrams AKA Interaction Diagrams – Semantically equivalent to Collaboration Diagrams AKA Interaction Diagrams – Semantically equivalent to Collaboration Diagrams Dynamic Model relating use cases and class diagrams Dynamic Model relating use cases and class diagrams Illustrates how objects interacts with each other Illustrates how objects interacts with each other Shows time ordering of interactions Shows time ordering of interactions Generally a set of messages between collaborating objects Generally a set of messages between collaborating objects Ordering of objects not significant Ordering of objects not significant

35 Sequence Diagrams Show only one flow of control Show only one flow of control Can model simple sequential flow, branching, iteration, recursion and concurrency Can model simple sequential flow, branching, iteration, recursion and concurrency May need multiple diagrams May need multiple diagrams Primary Primary Variant Variant Exceptions Exceptions

36 Sequence Diagram (Basic) Object : Class or Actor Lifeline message name X Object Destruction/ Termination > Focus of Control/ Activation

37 Sequence Diagram (Basic) Student aClass: Class Register :Scheduler adjustRoom checkRooms

38 Sequence Diagram (Basic) member: LibraryMember book:Book :Book Copy borrow(book) ok = mayBorrow() [ok] borrow(member) setTaken(member) X-Axis (objects) Y-Axis (time) Object Life Line message Activation box condition

39 Sequence Diagrams (Advanced) Seq# [Guard] *[Iteration] Return-List := Operation-Name (Argument-List) recursion *[Iteration Condition] Conditional Lifeline {transient}

40 Object Object naming: Object naming: syntax: [instanceName][:className] syntax: [instanceName][:className] Name classes consistently with your class diagram (same classes). Name classes consistently with your class diagram (same classes). Include instance names when objects are referred to in messages or when several objects of the same type exist in the diagram. Include instance names when objects are referred to in messages or when several objects of the same type exist in the diagram. The Life-Line represents the object’s life during the interaction The Life-Line represents the object’s life during the interaction myBirthdy :Date

41 Messages An interaction between two objects is performed as a message sent from one object to another (simple operation call, Signaling, RPC) An interaction between two objects is performed as a message sent from one object to another (simple operation call, Signaling, RPC) If object obj 1 sends a message to another object obj 2 some link must exist between those two objects (dependency, same objects) If object obj 1 sends a message to another object obj 2 some link must exist between those two objects (dependency, same objects)

42 Messages (Cont.) A message is represented by an arrow between the life lines of two objects A message is represented by an arrow between the life lines of two objects Self calls are also allowed Self calls are also allowed The time required by the receiver object to process the message is denoted by an activation-box The time required by the receiver object to process the message is denoted by an activation-box A message is labeled at minimum with the message name A message is labeled at minimum with the message name Arguments and control information (conditions, iteration) may be included Arguments and control information (conditions, iteration) may be included

43 Return Values Optionally indicated using a dashed arrow with a label indicating the return value. Optionally indicated using a dashed arrow with a label indicating the return value. Don’t model a return value when it is obvious what is being returned, e.g. getTotal() Don’t model a return value when it is obvious what is being returned, e.g. getTotal() Model a return value only when you need to refer to it elsewhere, e.g. as a parameter passed in another message. Model a return value only when you need to refer to it elsewhere, e.g. as a parameter passed in another message. Prefer modeling return values as part of a method invocation, e.g. ok = isValid() Prefer modeling return values as part of a method invocation, e.g. ok = isValid()

44 Sequence Diagram (Basic) getViolation(id) Clerk :Violations Dialog :Violations Controller :Violations DBProxy lookup viewButton() id=getID() v:Traffic Violation display(v) > v Lookup Traffic Violation May be a pseudo- method DB is queried and the result is returned as an object

45 Sequence Diagram (Basic) print(doc,client) Client :PrintServer:Queue :Printer Proxy enqueue(job) status job=dequeue() [job]print(job.doc) [job] done(status) Repeated forever with 1 min interludes Active object


Download ppt "UML Class Diagrams Sequence Diagrams CSE230 Dae-Kyoo Kim."

Similar presentations


Ads by Google