Designing Project Using UML Outline What is UML

  • Slides: 49
Download presentation
Designing Project Using UML

Designing Project Using UML

Outline § § § What is UML and why we use UML? How to

Outline § § § What is UML and why we use UML? How to use UML diagrams to design software system? What UML Modeling tools we use today?

What is UML and Why we use UML? § UML → “Unified Modeling Language”

What is UML and Why we use UML? § UML → “Unified Modeling Language” Ø Language: express idea, not a methodology Ø Ø Modeling: Describing a software system at a high level of abstraction Unified: UML has become a world standard Object Management Group (OMG): www. omg. org

What is UML and Why we use UML? § Ø Ø Ø More description

What is UML and Why we use UML? § Ø Ø Ø More description about UML: It is a industry-standard graphical language for specifying, visualizing, constructing, and documenting the artifacts of software systems The UML uses mostly graphical notations to express the OO analysis and design of software projects. Simplifies the complex process of software design

What is UML and Why we use UML? § Ø Why we use UML?

What is UML and Why we use UML? § Ø Why we use UML? Use graphical notation: more clearly than natural language (imprecise) and code (too detailed). Ø Help acquire an overall view of a system. Ø UML is not dependent on any one language or technology. Ø UML moves us from fragmentation to standardization.

What is UML and Why we use UML? Year Version 2003: UML 2. 0

What is UML and Why we use UML? Year Version 2003: UML 2. 0 2001: UML 1. 4 1999: UML 1. 3 1997: UML 1. 0, 1. 1 1996: UML 0. 9 & 0. 91 1995: Unified Method 0. 8 Booch ‘ 93 OMT - 2 Other methods Booch ‘ 91 OMT - 1

How to use UML diagrams to design software system? n Ø Ø Ø Types

How to use UML diagrams to design software system? n Ø Ø Ø Types of UML Diagrams: Use Case Diagram Class Diagram Sequence Diagram Collaboration Diagram State Diagram Activity Diagram This is only a subset of diagrams … but are most widely used

Use-Case Diagrams n n Ø Ø Ø n n n A use-case diagram is

Use-Case Diagrams n n Ø Ø Ø n n n A use-case diagram is a set of use cases A use case is a model of the interaction between External users of a software product (actors) and The software product itself More precisely, an actor is a user playing a specific role describing a set of user scenarios capturing user requirements contract between end user and software developers

Use-Case Diagram Boundary Actor Use Case Library System Borrow Employee Client Order Title Fine

Use-Case Diagram Boundary Actor Use Case Library System Borrow Employee Client Order Title Fine Remittance Relationship Supervisor

Use-Case Diagram n n Actor: A role that a user plays with respect to

Use-Case Diagram n n Actor: A role that a user plays with respect to the system, including human users and other systems. e. g. , inanimate physical objects (e. g. robot); an external system that needs some information from the current system. An actor may - input information to the system. - receive information from the system. - input to and out from the system. Use case: A set of scenarios that describing an interaction between a user and a system, including alternatives. System boundary: rectangle diagram representing the boundary between the actors and the system.

Use-Case Diagram Relationships Association Relationship – links an actor with the use case(s) extends

Use-Case Diagram Relationships Association Relationship – links an actor with the use case(s) extends Relationship <<extend>> – to model that one use case will extend the functionality to another use case. – arrow points to the calling use case includes Relationship <<include>> – to model that one use case will use the functionality of another use case. – arrow points to the include use case Generalization Relationship – Shows that one class (subclass) inherits from another class(superclass). – a line with a triangular arrow head toward the parent use case. <<extend>> <<include>>

Use-Case Diagram Figure 16. 12 The Mc. Graw-Hill Companies, 2005

Use-Case Diagram Figure 16. 12 The Mc. Graw-Hill Companies, 2005

n n n Both Make Appointment and Request Medication include Check Patient Record as

n n n Both Make Appointment and Request Medication include Check Patient Record as a subtask (include) The extension point is written inside the base case Pay bill; the extending class Defer payment adds the behavior of this extension point. (extend) Pay Bill is a parent use case and Bill Insurance is the child use case. (generalization)

Class diagram n A class diagram depicts classes and their interrelationships n Used for

Class diagram n A class diagram depicts classes and their interrelationships n Used for describing structure and behavior in the use cases n Provide a conceptual model of the system in terms of entities and their relationships n Used for requirement capture, end-user interaction n Detailed class diagrams are used for developers

Class diagram [from UML Distilled Third Edition]

Class diagram [from UML Distilled Third Edition]

Class diagram n Each class is represented by a rectangle subdivided into three compartments

Class diagram n Each class is represented by a rectangle subdivided into three compartments Ø Ø Ø n Modifiers are used to indicate visibility of attributes and operations. Ø Ø Ø n Name Attributes Operations ‘+’ is used to denote Public visibility (everyone) ‘#’ is used to denote Protected visibility (friends and derived) ‘-’ is used to denote Private visibility (no one) By default, attributes are hidden and operations are visible.

Class diagram Account_Name - Customer_Name - Balance +add. Funds( ) +with. Draw( ) +transfer(

Class diagram Account_Name - Customer_Name - Balance +add. Funds( ) +with. Draw( ) +transfer( ) Name Attributes Operations

Elements of a Class Diagram Association Class Multiplicity Watch 1 2 1 1 1

Elements of a Class Diagram Association Class Multiplicity Watch 1 2 1 1 1 2 1 Battery load Time now 1 Push. Button -state +push() +release() Attribute LCDDisplay -blink. Idx +blink. Seconds() +blink. Minutes() +blink. Hours() +stop. Blinking() +referesh() Operations

OO Relationships n There are two kinds of Relationships n n n Generalization (parent-child

OO Relationships n There are two kinds of Relationships n n n Generalization (parent-child relationship) Association (relationship of the classes) Associations can be further classified as n n Aggregation Composition

OO Relationships: Generalization Supertype Example: Regular Customer Subtype 1 Customer Loyalty Customer Subtype 2

OO Relationships: Generalization Supertype Example: Regular Customer Subtype 1 Customer Loyalty Customer Subtype 2 -Inheritance is a required feature of object orientation -Generalization expresses a parent/child relationship among related classes. -Used for abstracting details in several layers

Association n Represent relationship between instances of classes n n n Student enrolls in

Association n Represent relationship between instances of classes n n n Student enrolls in a course Courses have students Courses have exams Etc. Association has n n n Role names (e. g. enrolls) Multiplicity (e. g. One course can have many students) Navigability (unidirectional, bidirectional)

Association v Represents a relationship between multiple classes or a class and itself. v

Association v Represents a relationship between multiple classes or a class and itself. v Shows how the two classes are associated with each other v Is labeled using a verb phrase. Eg: takes, registers v It has multiplicity, which denote the minimum and maximum instances that can be related via the relationship. n Exactly one(1), zero or more (0. . *), one or more (1. . *) n Specified range (2. . 4), multiple, disjoint range (1. . 3, 5)

Association: Multiplicity and Roles student 1 * University Person 0. . 1 employer *

Association: Multiplicity and Roles student 1 * University Person 0. . 1 employer * teacher Role Multiplicity Symbol Meaning 1 One and only one 0. . 1 Zero or one M. . N From M to N (natural language) * From zero to any positive integer 0. . * From zero to any positive integer 1. . * From one to any positive integer Role “A given university groups many people; some act as students, others as teachers. A given student belongs to a single university; a given teacher may or may not be working for the university at a particular time. ”

Association: Model to Implementation Student * has Class Student { Course enrolls[4]; } Class

Association: Model to Implementation Student * has Class Student { Course enrolls[4]; } Class Course { Student have[]; } 4 enrolls Course

DISCOVERING RELATI 0 NSHIP AMONG CLASSES ASSOCIATION • represents a general binary relationship that

DISCOVERING RELATI 0 NSHIP AMONG CLASSES ASSOCIATION • represents a general binary relationship that describes an activity between two classes. Student 5. . 60 public class Student { /** Data fields */ private Course[] course. List; /** Constructors */ /** Methods */ } Take * Course 0. . 3 Teach public class Course { /** Data fields */ private Student[60] class. List; private Lecturer lecturer; /** Constructors */ /** Methods */ 1 Lecturer public class Lecturer{ /** Data fields */ private Course[3] course. List; /** Constructors */ /** Methods */ }

AGGREGATION This is a special type of association n The association with label “contains”

AGGREGATION This is a special type of association n The association with label “contains” or “is part of” is an aggregation n It represents "has a" relationship n It is used when one object logically or physically contains other n The container is called as aggregate n It has an empty diamond at its end n The components of aggregate can be shared with others n It expresses a whole - part relationships 27

AGGREGATION Example: “Customer has an ATM card” Customer ATM Card owner component 28

AGGREGATION Example: “Customer has an ATM card” Customer ATM Card owner component 28

COMPOSITION This is a strong form of aggregation n It expresses the stronger coupling

COMPOSITION This is a strong form of aggregation n It expresses the stronger coupling between the classes n The owner is explicitly responsible for creation and deletion of the part n Any deletion of whole is considered to cascade its part n The aggregate has a filled diamond at its end Automobile owner Engine component 29

Aggregation vs. Composition • Composition is really a strong form of aggregation • components

Aggregation vs. Composition • Composition is really a strong form of aggregation • components have only one owner • components cannot exist independent of their owner • components live or die with their owner e. g. Each car has an engine that can not be shared with other cars. • Aggregations may form "part of" the aggregate, but may not be essential to it. They may also exist independent of the aggregate. e. g. Apples may exist independent of the bag.

AGGREGATION & COMPOSITION • Represents the has‐a relationship. • If an object is exclusively

AGGREGATION & COMPOSITION • Represents the has‐a relationship. • If an object is exclusively owned by an aggregated object, the relationship between the object and its aggregated object is referred to as composition. Composition Name Person Aggregation Address

AGGREGATION & COMPOSITION • An aggregation relationship is usually represented as a data field

AGGREGATION & COMPOSITION • An aggregation relationship is usually represented as a data field in the aggregated class. public class Name { /** Data fields */ /** Constructors */ /** Methods */ } public class Person { /** Data fields */ private Name name; private Address address; /** Constructors */ /** Methods */ } public class Address { /** Data fields */ /** Constructors */ /** Methods */ }

Interface • A weak is‐a relationship can be represented using interfaces. public class Student

Interface • A weak is‐a relationship can be represented using interfaces. public class Student extends Person implements Comparable { Person Student Comparable (A) /** Data fields, Constructors, and */ /** Methods */ /** Implement the compare. To method */ public int compare. To(Object object) { //. . . } } (B)

Good Practice: CRC Card Class Responsibility Collaborator n easy to describe how classes work

Good Practice: CRC Card Class Responsibility Collaborator n easy to describe how classes work by moving cards around; allows to quickly consider alternatives.

Interaction Diagrams n n show objects interact with one another UML supports two types

Interaction Diagrams n n show objects interact with one another UML supports two types of interaction diagrams Ø Ø Sequence diagrams Collaboration diagrams

Sequence Diagram(make a phone call) Caller Phone Recipient Picks up Dial tone Dial Ring

Sequence Diagram(make a phone call) Caller Phone Recipient Picks up Dial tone Dial Ring notification Ring Picks up Hello

Sequence Diagram: Object interaction A Self-Call: A message that an Object sends to itself.

Sequence Diagram: Object interaction A Self-Call: A message that an Object sends to itself. Condition: indicates when a message is sent. The message is sent only if the condition is true. B Synchronous Asynchronous Transmission delayed [condition] remove() Condition *[for each] remove() Iteration Self-Call

Sequence Diagrams – Object Life Spans n n n Creation A Ø "Create" message

Sequence Diagrams – Object Life Spans n n n Creation A Ø "Create" message Ø Object life starts at that point Activation Ø Symbolized by rectangular stripes Ø Place on the lifeline where object is activated. Ø Rectangle also denotes when object is deactivated. Activation bar Deletion Ø Placing an ‘X’ on lifeline Ø Object’s life ends at that point Lifeline Create Return B X Deletion

Sequence Diagram Message • Sequence diagrams demonstrate the behavior of objects in a use

Sequence Diagram Message • Sequence diagrams demonstrate the behavior of objects in a use case by describing the objects and the messages they pass. • The horizontal dimension shows the objects participating in the interaction. • The vertical arrangement of messages indicates their order. • The labels may contain the seq. # to indicate concurrency.

Interaction Diagrams: Collaboration diagrams start 6: remove reservation 3 : [not available] reserve title

Interaction Diagrams: Collaboration diagrams start 6: remove reservation 3 : [not available] reserve title User Reservations 5: title available 6 : borrow title 2: title data 1: look up 4 : title returned Catalog 5 : hold title ØCollaboration diagrams are equivalent to sequence diagrams. All the features of sequence diagrams are equally applicable to collaboration diagrams ØUse a sequence diagram when the transfer of information is the focus of attention ØUse a collaboration diagram when concentrating on the classes

Activity Diagram n n n Activity diagrams represent the dynamic (behavioral) view of a

Activity Diagram n n n Activity diagrams represent the dynamic (behavioral) view of a system Activity diagrams are typically used for business (transaction) process modeling and modeling the logic captured by a single use-case or usage scenario Activity diagram is used to represent the flow across use cases or to represent flow within a particular use case UML activity diagrams are the object oriented equivalent of flow chart and data flow diagrams in function-oriented design approach Activity diagram contains activities, transitions between activities, decision points, synchronization bars, swim lanes and many more…

Basic Components in an Activity Diagram n n Initial node n The filled circle

Basic Components in an Activity Diagram n n Initial node n The filled circle is the starting point of the diagram Final node n The filled circle with a boarder is the ending point. An activity diagram can have zero or more activity final state. Activity n The rounded circle represents activities that occur. An activity is not necessarily a program, it may be a manual thing also Flow/ edge n The arrows in the diagram. No label is necessary

Basic Components in an Activity Diagram n n n Fork n A black bar

Basic Components in an Activity Diagram n n n Fork n A black bar ( horizontal/vertical ) with one flow going into it and several leaving it. This denotes the beginning of parallel activities Join n A block bar with several flows entering it and one leaving it. this denotes the end of parallel activities Merge n A diamond with several flows entering and one leaving. The implication is that all incoming flow to reach this point until processing continues

Basic Components in an Activity Diagram n n n Decision n A diamond with

Basic Components in an Activity Diagram n n n Decision n A diamond with one flow entering and several leaving. The flow leaving includes conditions as yes/ no state Activity Final Node n The activity final node indicates that an activity is completed. An activity diagram can have more than one exit in the form of activity final nodes: n If several parallel flows are present within an activity, all flows are stopped at the time the activity final node is reached. Activity Partition n The individual elements of an activity diagram can be divided into individual areas or 'partitions'. Various criteria can lead to the creation of these partitions: organization entities, cost centers, locations, etc:

Activity Diagram (Examination Process Example)

Activity Diagram (Examination Process Example)

State Diagrams (Billing Example) State Diagrams show the sequences of states an object goes

State Diagrams (Billing Example) State Diagrams show the sequences of states an object goes through during its life cycle in response to stimuli, together with its responses and actions; an abstraction of all possible behaviors. End Start Unpaid Invoice created Paid paying Invoice destroying

State Diagrams (Traffic light example) Traffic Light State Transition Red Yellow Green Event Start

State Diagrams (Traffic light example) Traffic Light State Transition Red Yellow Green Event Start

What UML Modeling tools we use today? n List of UML tools http: //en.

What UML Modeling tools we use today? n List of UML tools http: //en. wikipedia. org/wiki/List_of_UML_tools n Argo. UML: http: //argouml. tigris. org/ n Rational Rose (www. rational. com) by IBM n n UML Studio 7. 1 ( http: //www. pragsoft. com/) by Pragsoft Corporation: Capable of handling very large models (tens of thousands of classes). Educational License US$ 125. 00; Freeware version. Together. Soft Control Center; Together. Soft Solo (http: //www. borland. com/together/index. html) by Borland

Conclusion n n Ø Ø Ø n UML is a standardized specification language for

Conclusion n n Ø Ø Ø n UML is a standardized specification language for object modeling Several UML diagrams: Use-case diagram: a number of use cases (use case models the interaction between actors and software) Class diagram: a model of classes showing the static relationships among them including association and generalization. Sequence diagram: shows the way objects interact with one another as messages are passed between them. Activity diagram: represent the flow across use cases or to represent flow within a particular use case State diagram: shows states, events that cause transitions between states. Another dynamic model reflecting the behavior of objects and how they react to specific event There are several UML tools available

Thank you Questions?

Thank you Questions?