Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 2511 Fall 2014. UML Diagram Types  2 Main Types Structure Diagrams ○ Class Diagrams ○ Component Diagrams ○ Object Diagrams Behavior Diagrams ○ Sequence.

Similar presentations


Presentation on theme: "CS 2511 Fall 2014. UML Diagram Types  2 Main Types Structure Diagrams ○ Class Diagrams ○ Component Diagrams ○ Object Diagrams Behavior Diagrams ○ Sequence."— Presentation transcript:

1 CS 2511 Fall 2014

2 UML Diagram Types  2 Main Types Structure Diagrams ○ Class Diagrams ○ Component Diagrams ○ Object Diagrams Behavior Diagrams ○ Sequence Diagrams ○ Use Case Diagrams

3 Class Diagrams  Type of static structure diagram  Describes: The structure of a system by showing the system’s classes The class attributes The relationships between classes

4 Class Node Layout Class Name Attributes of Class (Data Members) Operations of Class (Member Functions)

5 Example Class Diagram Revisited public class Circle { private double radius; private double area; protected double getArea(); public void setCenter(Point); public Point center; } Circle radius : double area : double center : Point getArea() : double setCenter(Point)

6 Visibility Specifiers  To specify the visibility of a class member (both attributes and methods) use the following before the member's name: public: + protected: # private: - package: ~

7 Example Class Diagram Revisited public class Circle { private double radius; private double area; protected double getArea(); public void setCenter(Point); public Point center; } Circle - radius: double - area: double + center: Point # getArea() : double + setCenter(Point)

8 Class Relationships  A relationship is a general term covering the specific types of logical connections found on class and object diagrams.  We’ll look at the following: Dependency Aggregation Inheritance

9 Dependency  A very weak relationship  A class depends on another class if it manipulates objects of the other class

10 UML Dependency Shape - var1 : Point + draw(Circle c) Circle - radius: double - area: double + center: Point # getArea() : double + setCenter(Point)

11 Dependency in Code public class Shape { public void draw(Circle c); private Point var1; // Some other variables and methods … } public class Circle { private double radius; private double area; protected double getArea(); public void setCenter(Point); public Point center; } Notice that draw(Circle c) is the only reference to class Circle in Shape, so a weak relationship

12 Aggregation  A class aggregates another if its objects contain objects of the other class.  The aggregate class (the class with the white diamond touching it) is in some way the “whole,” and the other class in the relationship is somehow “part” of that whole. Mailbox - messages : ArrayList Message *

13 Aggregation in Code public class Mailbox { private ArrayList messages; // Other Variables and Methods Go Here } public class Message { // Variables and Methods Go Here } Note that this is a 1 to many relationship since for every Mailbox there are 0 or more messages stored

14 Inheritance  A class inherits from another if it incorporates the behavior of the other class  Special Cases of objects of the parent class type  (Possibly) capable of exhibiting additional responsibilities

15 UML Inheritance Child + method2() Parent + method1() Note only methods new to Child are listed in Child class (not methods inherited from Parent)

16 Inheritance in Code public class Parent { public void method1(); } public class Child extends Parent { public void method2(); }

17 CS 2511 Fall 2014

18 UML Diagram Types  2 Main Types Structure Diagrams ○ Class Diagrams ○ Component Diagrams ○ Object Diagrams Behavior Diagrams ○ Sequence Diagrams ○ Use Case Diagrams

19 Sequence Diagrams sequence diagram  A sequence diagram in Unified Modeling Language (UML) is a kind of interaction diagram that shows how processes operate with one another and in what order. objects  In Java most of the interaction between processes is done via objects, and thus a sequence diagram basically shows how objects interact with other objects.

20 Organization Object Name: Class Name :Class NameObject Name Method Call

21 Object  Each box represents an Object that is alive (i.e. it’s constructor has been called) at a particular time in the computation.  3 options to represent objects : Object Name: Class Name :Class NameObject Name

22 LifeLines  The time for which an object is “alive” i.e. still in scope (which means has not been garbage collected yet) is represented by a life line. smallCircle :Circle

23 Activation Bars  Activation bars are used to represent the time when an object is calling a method.  The activation bars ends when the method that was called returns. smallCircle :Circle myMonitor: Display methodCall( ) Returned from method

24 Call Arrows and Method Names  A call is represented by an arrow going from one object to another.  Method Names are represented on the call arrow. :BridgeProblem currentState :BridgeState >

25 Examples  Code : public static void main(String[] args) { BridgeState initialState = new BridgeState("west", "west", "west", "west", "west", 0); BridgeState finalState = new BridgeState("east", "east", "east", "east", "east", 17); initialState.display(); finalState.display(); }

26 Sequence Diagram initialState: BridgeState > finalState: BridgeState > display() BridgeTest1. main


Download ppt "CS 2511 Fall 2014. UML Diagram Types  2 Main Types Structure Diagrams ○ Class Diagrams ○ Component Diagrams ○ Object Diagrams Behavior Diagrams ○ Sequence."

Similar presentations


Ads by Google