Class diagrams. Modeling with UML Chapter 2, part 2. Class Diagrams: details. Class diagram for a simple watch

Similar documents
Class diagrams. Modeling with UML Chapter 2, part 2. Class Diagrams: details. Class diagram for a simple watch

Unified Modeling Language (UML) Class Diagram

Chapter 10. Object-Oriented Analysis and Modeling Using the UML. McGraw-Hill/Irwin

UML Sequence Diagrams for Process Views

Sequence Diagrams. Massimo Felici. Massimo Felici Sequence Diagrams c

What is a Class Diagram? A diagram that shows a set of classes, interfaces, and collaborations and their relationships

What is a Class Diagram? Class Diagram. Why do we need Class Diagram? Class - Notation. Class - Semantic 04/11/51

Question Sheet There are a number of criticisms to UML. List a number of these criticisms.

Practical UML - A Hands-On Introduction for Developers

Unified Modeling Language (UML)

UML Fundamental. OutLine. NetFusion Tech. Co., Ltd. Jack Lee. Use-case diagram Class diagram Sequence diagram

Object-Oriented and Classical Software Engineering

CS 370 REVIEW: UML Diagrams D R. M I C H A E L J. R E A L E F A L L

Practical UML : A Hands-On Introduction for Developers

LABORATORY 1 REVISION

Chapter 2: The Object-Oriented Design Process

Principles of Software Construction: Objects, Design and Concurrency. Just enough UML. toad

Meltem Özturan

Interaction Modelling: Sequence Diagrams

CS211 Lecture: Modeling Dynamic Behaviors of Systems; Interaction Diagrams in UML

Modeling with UML. (1) Use Case Diagram. (2) Class Diagram. (3) Interaction Diagram. (4) State Diagram

UML Tutorial. Unified Modeling Language UML Tutorial

Interactions A link message

OO System Models Static Views

12 Tutorial on UML. TIMe TIMe Electronic Textbook

Lesson 11. W.C.Udwela Department of Mathematics & Computer Science

Software Service Engineering

A - 1. CS 494 Object-Oriented Analysis & Design. UML Class Models. Overview. Class Model Perspectives (cont d) Developing Class Models

CS211 Lecture: Modeling Dynamic Behaviors of Systems; Interaction Diagrams and Statecharts Diagrams in UML

Lecture 21 Detailed Design Dynamic Modeling with UML

Object Oriented Methods with UML. Lecture -4

Basic Structural Modeling. Copyright Joey Paquet,

CSCI 253. Outline. Rationale. George Blankenship 1. Object Oriented Design: UML. George Blankenship

UML. By Somenath Mukhopadhyay.

Developing Shlaer-Mellor Models Using UML

Chapter No. 2 Class modeling CO:-Sketch Class,object models using fundamental relationships Contents 2.1 Object and Class Concepts (12M) Objects,

Chapter 5: Structural Modeling

Object Oriented Design. Program Design. Analysis Phase. Part 2. Analysis Design Implementation. Functional Specification

CSE 308. UML Sequence Diagrams. Reading / Reference.

Object Oriented Modeling

Introducing the UML Eng. Mohammed T. Abo Alroos

Course "Softwaretechnik" Book Chapter 2 Modeling with UML

CS 451 Software Engineering

UNIT-IV BASIC BEHAVIORAL MODELING-I

COSC 3351 Software Design. An Introduction to UML (I)

The Essence of Object Oriented Programming with Java and UML. Chapter 2. The Essence of Objects. What Is an Object-Oriented System?

+ Public - Private # Protected # Protected (Overridable) Static

S T R U C T U R A L M O D E L I N G ( M O D E L I N G A S Y S T E M ' S L O G I C A L S T R U C T U R E U S I N G C L A S S E S A N D C L A S S D I A

Introduction to Software Engineering. 5. Modeling Objects and Classes

Object Mentor, Inc. Or How Uncle Bob uses UML. Copyright by Object Mentor, Inc All Rights Reserved

Engineering Design w/embedded Systems

Object-Oriented Software Engineering Practical Software Development using UML and Java

SOFTWARE DESIGN COSC 4353 / Dr. Raj Singh

Lecture 17: (Architecture V)

UML REFERENCE SHEETS. 2013, 2014 Michael Marking; all rights reserved, including moral rights. Web site:

CMPT 354 Database Systems I

Lab Manual. Object Oriented Analysis And Design. TE(Computer) VI semester

For 100% Result Oriented IGNOU Coaching and Project Training Call CPD TM : ,

Unified Modeling Language

OBJECT ORIENTED DESIGN with the Unified Process. Use Case Realization

OO Techniques & UML Class Diagrams

Class Diagram. Classes consist of. Note that class diagrams contain only classes, not objects.

Software Design Models, Tools & Processes. Lecture 3: Addendum Cecilia Mascolo

UNIT-4 Behavioral Diagrams

CSE 403: Software Engineering, Spring courses.cs.washington.edu/courses/cse403/15sp/ UML Class Diagrams. Emina Torlak

Object-Oriented Systems Analysis and Design Using UML

Progress Report. Object-Oriented Software Development: Requirements elicitation (ch. 4) and analysis (ch. 5) Object-oriented software development

Class Diagram. Classes consist of. Note that class diagrams contain only classes, not objects.

CSE 403 Lecture 8. UML Class Diagrams. Thanks to Marty Stepp, Michael Ernst, and other past instructors of CSE 403

Ali Khan < Project Name > Design Document. Version 1.0. Group Id: S1. Supervisor Name: Sir.

Use Case Sequence Diagram. Slide 1

Unified Modeling Language (UML)

OBJECT ORIENTED DESIGN with the Unified Process. Use Case Realization

administrivia today UML start design patterns Tuesday, September 28, 2010

Progress Report. Object-Oriented Software Development: Requirements elicitation and analysis. Object-oriented analysis, design, implementation

Object-Interaction Diagrams: Sequence Diagrams UML

Today s Topic. Lecture 5. What is UML? Why Use UML. UML Diagrams. Introduction to UML. What is UML Why use UML? UML Diagrams

Chapter 2, lecture 2 Modeling with UML

Chapter 1: Principles of Programming and Software Engineering

SOFTWARE ENGINEERING UML FUNDAMENTALS. Saulius Ragaišis.

Requirements Engineering

Pieter van den Hombergh. Fontys Hogeschool voor Techniek en Logistiek. September 9, 2016

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Objectives. Explain the purpose and objectives of objectoriented. Develop design class diagrams

Credit where Credit is Due. Lecture 4: Fundamentals of Object Technology. Goals for this Lecture. Real-World Objects

EE 446 EMBEDDED ARCHITECTURE Embedded System in UML (2)

Design and UML Class Diagrams

Intro to DB CHAPTER 6

UML UNIFIED MODELLING LANGUAGE EXEMPLIFIED ON BLACKJACK. Object Oriented Programming (Samy Zafrany)

UML Component Diagrams A.Y 2018/2019

SE 1: Software Requirements Specification and Analysis

Object-Oriented Modeling. Sequence Diagram. Slides accompanying Version 1.0

Entity Relationship Modelling

The learning objectives of this chapter are the followings. At the end of this chapter, you shall

Architecture and the UML

The Next Step: Designing DB Schema. Chapter 6: Entity-Relationship Model. The E-R Model. Identifying Entities and their Attributes.

NOTES ON OBJECT-ORIENTED MODELING AND DESIGN

Design Engineering. Dr. Marouane Kessentini Department of Computer Science

Object-Oriented Design and Modeling Using the UML

Modeling Dynamic Behavior

Transcription:

Class diagrams Modeling with UML Chapter 2, part 2 CS 4354 Summer II 2015 Jill Seaman Used to describe the internal structure of the system. Also used to describe the application domain. They describe the system in terms of Classes, an abstract representation of a set of objects Attributes, properties of the objects in a class Operations that can be performed on objects in a class Associations that can occur between objects in various classes 1 2 Class diagram for a simple watch Class Diagrams: details Classes are boxes composed of three compartments: Top compartment: name Center compartment: attributes Bottom compartment: operations Boxes are classes Lines show associations (between objects) Numbers show how many objects must be associated This diagram does not show attributes or operations Lines between classes represent associations between classes These can have role names and multiplicity constraints Conventions: Class names start with uppercase letter Attributes can (and should) have types specified Attributes and Operations are sometimes omitted for simplicity 3 4

UML class diagram: classes that participate in the ReportEmergency use case. Associations and links A link is some connection between two objects. Associations are relationships between classes and represent the fact that links may (or do) exist between object instances. Associations are noted with a line between the boxes. Associations can be symmetrical (bidirectional) or asymmetrical (unidirectional). Unidirectional association is indicated by using a line with an arrow The arrow indicated in which direction navigation is supported. If the line has no arrows, it s assumed to be bidirectional. 5 6 Roles Multiplicity Each end of an association can be labeled by a role. Allows us to distinguish among the multiple associations originating from a class. An employee can belong to a department and be the head of the department. Roles clarify the purpose of the association. If there is no role name specified, you can use the name of the class at the unspecified end. Previous diagram: The FieldOfficers who generate reports are called authors (or the author of the report). Multiplicity: a set of integers labeling one end of an association Indicates how many links can originate from an instance of the class at the other end of the association. This is generally an upper bound. * is shorthand for 0..n, called many Most associations belong to one of these three types: A one-to-one association has a multiplicity 1 on each end. A one-to-many association has a multiplicity 1 on one end and 0..n or 1..n on the other. A many-to-many association has a multiplicity 0..n or 1..n on both ends. 7 8

Example of a unidirectional association Examples of multiplicity CourseSection * Student This system supports navigation from the Polygon to the Point, but not vice versa. Given a specific Polygon, it is possible to query all Points that make up the Polygon. But a given Point does not know which Polygon(s) it belongs to. *Note: the diagram in the book is wrong, it has two arrows. 1 A CourseSection contains many Students A Student is enrolled in many CourseSections How many reports can a FieldOfficer write? How many authors of a report can there be? 9 10 Association class Aggregation and Composition Association class: an association with attributes and/or operations Depicted by a class symbol that contains the attributes and operations and is connected to the association symbol with a dashed line. Aggregation is a kind of association that specifies a whole/part relationship between the aggregate (whole) and component part. Useful to denote hierarchical relationships (directory contains files) Specified with an open diamond on the aggregate (whole) side. Composition is a special case of aggregation where the composite object has sole responsibility for the life cycle of the component parts. The composite is responsible for the creation and destruction of the component parts. An object may be part of only one composite. These kinds of classes are not commonly used. 11 Specified with a closed diamond on the composite (whole) side. 12

Examples of a aggregations Inheritance (or generalization) Inheritance is a relationship between a base class and a more refined class. the refined class has attributes and operations of its own, as well as the attributes and operations of the base class (it inherits them). Abstract class: name in italics Could any of these be composites? can a County belong to more than one State? can a County exist without a State? 13 14 Inheritance example Example of a hierarchical file system Doctor Name Phone # Email register ( ) de-register ( ) Note the operations Overridden operations are not shown Hospital doctor Staff # Pager # General practitioner Practice Address 15 16

Associations are not attributes! Attributes are like associations Do not add an attribute to a class to represent the end of an association already in the diagram Among other problems, this is redundant Associations in a diagram do NOT specify how they should be implemented There are various ways to record in an implementation the fact that one object is related to another. One class may contain a reference to an object it is associated with One class may contain a list of the objects it is associated with The class may run a method/function to determine which objects it is associated with. A Customer s name attribute indicates that a Customer has a name The name type might even be a Class, like a String The attribute types are usually small, simple classes The attribute usually has only one value, often its own copy In UML, the syntax of an attribute is: visibility name : type = defaultvalue visibility, type and defaultvalue are optional visibility: + (public), # (protected), or - (private) 17 18 Operations Class diagram with an interface An operation is a process that a class knows how to carry out Normally we don t show the setters and getters, these can often be inferred In UML, the syntax of an operation is: visibility name (parameter-list) : return-type visibility: + (public), # (protected), or - (private) parameter-list contains comma separated parameters, with syntax like attributes. An operation is something that is invoked on an object (like a signature or prototype), without a definition. So overriding definitions are generally not shown in the class diagram Interface: labelled with <<interface>> Implementors: point to the interface using dashed, open arrow 19 20

When and how to use Class Diagrams All the time. Try to keep them simple, don t use unnecessary notation. Especially if you are using them to model the application domain. If you want to specify the implementation very specifically, you will use more of the notation. Don t draw models for every part of the program (at least not all in great detail) Focus first on concepts, then add detail as the design process continues. Sequence Diagrams Represent the dynamic behavior of the system In UML, Interaction diagrams are models that describe how groups of objects collaborate in some behavior. There are two kinds of Interaction diagrams: Sequence Diagrams Collaboration Diagrams (we will not talk about these). Both of these diagrams describe patterns of communication among a set of interacting objects. 21 22 Sequence Diagrams: basics Sequence diagram for a simple watch An object of a given class is shown as a box at the top of a dashed vertical line. The dashed line is the lifeline, representing the object s lifetime. An object interacts with another object by sending messages. The message must be an operation of the receiving object. The message is shown as an arrow between the lifelines of the object Arguments may be passed along with a message they correspond to the parameters of the receiver s operation. variables can be used to label the return value of the operation 23 Actor and objects (not classes) across the top Vertical lines are lifelines of the objects Labeled arrows are messages sent to another object 24

Objects, lifelines, and activation boxes Messages and return arrows Objects are represented with a box containing a name and the Class the object is an instance of. name : Class The underline indicates this is an object, not a class. Only one part (the name or the Class) is required to be specified. The dotted line below the object is the object s lifeline Vertical rectangle: an activation box representing the duration of an operation. There must be a message pointing to the top of the box indicating the operation the box corresponds to. Messages are represented with a solid horizontal arrow from one object s lifeline to another. The call originates in the object at the source of the arrow It is received by the object at the end of the arrow The order in which the messages occur is top to bottom on the page. The message must be labeled with the name, but can also include the arguments, and a variable to label the operation s result value. Return arrows are dashed arrows from the bottom of the activation box back to the lifeline of the object that sent the initial message. These are optional! They might be labeled with the return value (rather than using a variable) 25 26 Self-call and Create new Iteration and branching Self-call (object calls one of its own methods) Message arrow back to original activation: Notation for iteration (loops) Repeated message has an asterisk ( *op3( ) ) Optional: indicate basis of iteration in brackets: *[for all order lines] op3() Creating new instances: new Class() message points to object s box: Notation for branching (alternatives) Conditional messages are marked with a guard (a condition inside square brackets) OR Alternative messages are placed in a partitioned box labeled alt each partition has a guard new Mailbox() May be easier to draw a separate diagram for each alternative If you really want to model control flow, you should use an activity diagram instead. 27 28

Branching and iteration in sequence diagrams. Using alt box to show branching. Medical Receptionist A window from the user interface Arrows with common start point are mutually exclusive alternatives ViewInfo (PID) P: PatientInfo report (Info, PID, UID) D: MHCPMS-DB AS: Authorization authorize (Info, UID) authorization PID: patient ID UID: user ID Info: kind of info to be returned alt [authorization OK] Patient info [authorization fail] Error (no access) 29 30 Sequence Diagrams: good practices The sequence diagram must be consistent with a given class diagram that fully specifies the classes and their operations messages to an object s lifeline must correspond to valid operations for that object s class; arguments must be specified, and return values labeled. Arguments should be defined somewhere in the diagram: A Name of another object in the diagram, An attribute of another object or A variable labeling the result of a previous message call. Activation boxes should not overlap horizontally unless one box s message has called the other. 31 32

Sequence diagrams for concurrency/threads asynchronous messages are represented with a half-arrowhead. An asynchronous message does not block the caller, it continues simultaneously. It is ok for activation boxes to overlap horizontally if one is not called from another. An asynchronous message can do one of three things: Create a new thread, linking to the top of an activation Create a new object Communicate with a thread that is already running Object deletion is shown with a large X. Note: GUIs are often asynchronous. 33 34 When and how to use Sequence Diagrams When you want to look at the behavior of several objects within a single use case. When the order of the method calls in the code seems confusing. When you are trying to determine which class should contain a given method. to uncover the responsibilities of the classes in the class diagrams to discover even new classes During Object-Oriented Design, sequence diagrams and the class diagram are often developed in tandem. 35