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

Similar documents
UML class diagrams. Nigel Goddard. School of Informatics University of Edinburgh

Class diagrams and architectural design

Introduction to Software Engineering. 5. Modeling Objects and Classes

Introduction to Software Engineering. 5. Modeling Objects and Classes

Basic Structural Modeling. Copyright Joey Paquet,

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

Chapter 5: Structural Modeling

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

SE 1: Software Requirements Specification and Analysis

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

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

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

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

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

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

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

12 Tutorial on UML. TIMe TIMe Electronic Textbook

Äriprotsesside modelleerimine ja automatiseerimine Loeng 7 Valdkonna mudel

Course "Softwaretechnik" Book Chapter 2 Modeling with UML

Object-Oriented Systems Development: Using the Unified Modeling Language

UML Modeling I. Instructor: Yongjie Zheng September 3, CS 490MT/5555 Software Methods and Tools

SOFTWARE DESIGN COSC 4353 / Dr. Raj Singh

Object-Oriented Analysis and Design. Pre-UML Situation. The Unified Modeling Language. Unification Efforts


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

Software Engineering Lab Manual

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

Class modelling (part 2)

Introducing the UML Eng. Mohammed T. Abo Alroos

Introduction to UML What is UML? Motivations for UML Types of UML diagrams UML syntax Descriptions of the various diagram types Rational Rose (IBM.. M

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) MODEL ANSWER

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Goal: build an object-oriented model of the realworld system (or imaginary world) Slicing the soup: OOA vs. OOD

Chapter 2: Entity-Relationship Model

Software Service Engineering

Engineering Design w/embedded Systems

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

LABORATORY 1 REVISION

Unified Modeling Language (UML) Class Diagram

Developing Shlaer-Mellor Models Using UML

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

Design and UML Class Diagrams

Bouml Tutorial. The tutorial must be read in order because I will not repeat each time the general commands to call a menu etc...

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 5: Modelling with Classes

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

Chapter 2: The Object-Oriented Design Process

Object Oriented Software Development CIS Today: Object Oriented Analysis

MSO Analysis & UML. Hans Philippi (based on the course slides of Wouter Swierstra) August 24, Analysis & UML 1 / 56

Design Engineering. Dr. Marouane Kessentini Department of Computer Science

Class modelling (part 2)

ACS-3913 Ron McFadyen 1. UML Notation for Class diagrams Object diagrams

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

Object Oriented Modeling and Design

UML: Unified Modeling Language

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

Lecture 33 April 4, Unied Modelling Language. ECE155: Engineering Design with Embedded Systems Winter Patrick Lam version 1

Course 3 7 March

Introduction to Unified Modelling Language (UML)

Software Engineering I (02161)

UNIT 5 - UML STATE DIAGRAMS AND MODELING

Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition. Chapter 7 Data Modeling with Entity Relationship Diagrams

Chapter 11 Object and Object- Relational Databases

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

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

Architecture and the UML

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

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

Relationships. Association Aggregation/Composition Multiplicity Dependencies

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

Chapter 10 Object-Oriented Design Principles

Component Design. Systems Engineering BSc Course. Budapest University of Technology and Economics Department of Measurement and Information Systems

ER modeling. Lecture 4

Entity Relationship Modelling

Conceptual Design with ER Model

Objectives. UML Extension Mechanisms. What is UML? Is the UML enough? UML Extension Mechanisms. Specifications. By Jasmine Farhad

UML Class Diagrams Revisited

Formal Methods in Software Engineering 1

Software Development Cycle. Unified Modeling Language. Unified Modeling Language. Unified Modeling Language. Unified Modeling Language.

Modelling with Classes. CITS1220 Software Engineering

Vidyalankar. T.Y. Diploma : Sem. VI [IF/CM] Object Oriented Modeling and Design Prelim Question Paper Solution

Chapter 7: Entity-Relationship Model

Pertemuan 8. Object Oriented Modeling and Design

Structural specification

Chapter 7: Entity-Relationship Model

Unified Modeling Language

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

UML Is Not a Methodology

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

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

UML Tutorial. Unified Modeling Language UML Tutorial

Chapter 7: Entity-Relationship Model

CTIS 359 Principles of Software Engineering SOFTWARE DESIGN OO(A)D

Object-Oriented and Classical Software Engineering

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

CHAPTER 1. Topic: UML Overview. CHAPTER 1: Topic 1. Topic: UML Overview

SOFTWARE ENGINEERING UML FUNDAMENTALS. Saulius Ragaišis.

COP 3330 Final Exam Review

Introduction to Computers and Programming Languages. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Enhanced Entity- Relationship Models (EER)

Transcription:

CS 494 Object-Oriented Analysis & Design UML Class Models Overview How class models are used? Perspectives Classes: attributes and operations Associations Multiplicity Generalization and Inheritance Aggregation and composition Later: How to find classes small and larger systems 200 T. Horton 2/7/00 G- 2/7/00 G-2 Developing Class Models Class diagrams developed iteratively Details added over time during lifecycle Initially: missing names, multiplicities, other details Some define particular perspectives for class models: Conceptual Specification Implementation Conceptual perspective Represents concepts in the domain Drawn with no regard for implementation (language independent) Used in requirements analysis Class Model Perspectives (cont d) Specification Interfaces defined: a set of operations But, each implementation class can include more than one interface A given interface can be shared by more than one class Sometimes known as a type Implementation Direct code implementation of each class in the diagram A blue-print for coding 2/7/00 G-3 2/7/00 G-4 Documenting Your Objects Classes in UML Diagrams Need some kind of record of your definitions Your white-board? A simple glossary A data dictionary (perhaps in a CASE tool) What to define? Attributes, operations for each class Also relationships between classes Can you define classes of related objects? Inheritance, Java interfaces 2/7/00 G-5 Attributes in middle Operations at bottom Can be suppressed. (What level of abstraction?) Attribute syntax: name : type = default Operation syntax: name ( params) : return type Visibility + public - private # protected etc. nothing? Java s defaultpackage? Book +title : string Book -title : string +borrow(c : Copy) : void +copiesonshelf() : int +gettitle() : string 2/7/00 G-6 A -

Associations For real-world objects is there an association between classes? Classes A and B are associated if: An object of class A sends a message to an object of B An object of class A creates an instance of class B An object of class A has an attribute of type B or collections of objects of type B An object of class A receives a message with an argument that is an instance of B (maybe ) Will it use that argument? Does an object of class A need to know about some object of class B? 2/7/00 G-7 More on Associations Associations should model the reality of the domain and allow implementation Associations are between classes A link connects two specific objects Links are instances of associations Note we could draw an object diagram to show objects and links But often interaction diagrams are more useful for modeling objects Note: In practice, early in modeling, we may not name associations Note: One may choose to have a dynamic view associations: if at run-time two objects exchange messages, their classes must be associated 2/7/00 G-8 Multiplicity Examples of Associations Also known as cardinality Objects from two classes are linked, but how many? An exact number: indicated by the number A range: two dots between a pair of numbers An arbitrary number: indicated by symbol (Rare) A comma-separated list of ranges Examples:..2 0.... (same as 0.. but ) Important: If class A has association X with class B The number of B s for each A is written next to class B Or, follow the association past the name and then read the multiplicity Implementing associations depends on multiplicity 2/7/00 G-9 From a Library catalog example One book has or more copies One copy is linked to exactly one book Should there be two associations: borrows and returns? One copy is borrowed by either zero or one LibraryMember Book Is A Copy Of.. Copy 0.. Borrows/Returns 0.. LibraryMember 2/7/00 G-0 Generalization and Inheritance Aggregation and Composition You may model inheritance early but not implement it Generalization represents a relationship at the conceptual level Inheritance is an implementation technique Generalization is just an association between classes But so common we put a triangle at the superclass Note this is a relationship between classes So no multiplicities are marked. Why not? Inheritance may not be appropriate when it s time to implement Objects should never change from one subclass to another Composition can be used instead 2/7/00 G- Again, just a specific kind of association between classes An object of class A is part of an object of class B A part-whole relationship Put a diamond on the end of the line next to the whole Aggregation (hollow diamond): really no semantics about what this means! Composition (solid diamond): a stronger relationship 2/7/00 G-2 A - 2

Aggregation and Composition (cont d) Example : University Courses Composition The whole strongly owns the parts Parts are copied (deleted, etc.) if the whole is copied (deleted, etc.) A part cannot be part of more than one whole Mnemonic: the stronger relationship is indicated by the stronger symbol (it s solid) Aggregation and composition associations are not named They do have multiplicities They can be used too often. If in doubt, use a Some instructors are professors, while others have job title adjunct Departments offer many courses, but a course may be offered by > department Courses are taught by instructors, who may teach up to three courses Instructors are assigned to one (or more) departments One instructor also serves a department chair plain, named association. 2/7/00 G-3 2/7/00 G-4 Class Diagram for Univ. Courses Example 2: Problem Report Tool Department.. offers Course 0.. teaches.. 0..3 chairs.. assigned to.. Adjunct Instructor Professor A CASE tool for storing and tracking problem reports Each report contains a problem description and a status Each problem can be assigned to someone Problem reports are made on one of the artifacts of a project Employees are assigned to a project A manager may add new artifacts and assign problem reports to team members Note this implies adjuncts can be chairs 2/7/00 G-5 2/7/00 G-6 Class Diagram for Prob. Rep. Tool Example from Fowler 0.. Employee.. Assigned To Project Artifact +name : string +name : string 0.. +name : string +status : enum Responsible For 0..n About Manager Developer Problem Report 0..n 0.. Managed By History Log 0..n History Entry Code Bug Report -when : Date -whatdone : string 2/7/00 G-7 2/7/00 G-8 A - 3

Objects, Object Diagrams Class Attributes, Operations Objects drawn like classes, but names for all instances underlined Objects may be anonymous Attributes are given values Recall in Java and C++ you may have class attributes and class operations keyword static used One attribute for all members of class An operation not encapsulated in each object, but defined in that class scope In UML class diagrams, list these in the class box s compartments, but underline them 2/7/00 G-9 2/7/00 G-20 Navigability More on Associations: Navigability Some call this direction of visibility Does each class really store a reference to each other? Do we need to decide this now? (When is now?) We can add arrows to associations to indicate this What does a line with no arrows mean? One reason for having an association between classes: Messages between objects of those classes But, often knowledge indicated by association is only in one direction Example: In a computer system, a User needs access to his/her Password From a Password object we should not be able to get back to a User! Note: Often ignored until design! 2/7/00 G-2 2/7/00 G-22 More on Associations: Roles Review: Associations have an optional name Name might have a direction indicator But, direction or semantics often easier to understand if we simply but a role name at one or both ends of the line Student Student advisee advises advisor Professor Professor 2/7/00 G-23 Dependencies Dependency: A using relationship between two classes A change in the specification of one class may affect the other But not necessarily the reverse Booch says: use dependencies not associations when one class uses another class as an argument in an operation. Often used for other things in UML: A general relationship between things in UML Often use a stereotype to give more info Uses: binding C++ class to template; Java interfaces; a class only instantiates objects (a factory) 2/7/00 G-24 A - 4

Stereotypes Stereotypes (cont d) Extends the vocabulary of UML Creates a new kind of building block Derived from existing UML feature But specific for current problem Also, some pre-defined stereotypes UML allows you to provide a new icon! Syntax: Above name add <<stereotype>> inside guillemets (French quotes) Again, used to provide extra info about the UML modeling construct UML predefines many: Classes: <<interface>>, <<type>>, <<implementationclass>>, <<enumeration>>, <<thread>> Constraints: <<precondition>> etc. Dependencies: <<friend>>, <<use>> Comments: <<requirement>>, <<responsibility>> Packages: <<system>>, <<subsystem>> (maybe classes, too) Or, create your own if needed. 2/7/00 G-25 2/7/00 G-26 You can use stereotypes to organize things by category within a class box Class Categories Stereotype Example «Interface» IStringifiable stringify() : string «use» Module prints IStringifiable is not a class Printer Interface (as in Java) Module implements this interface Printer depends on what s in the interface 2/7/00 G-27 2/7/00 G-28 Interfaces Interface Example Diagram Interface: specifies a set of operations that any class implementing or realizing the interface must provide More than one class may realize one interface One class may realize more than one interface No attributes, and no associations Notation: Use <<interface>> with a class; list operations Lollipop notation 2/7/00 G-29 2/7/00 G-30 A - 5

Classes Realize an Interface Realizes AKA implements, supports, matches, etc. This means that class provides all the operations in the interface (and more?) Remember, no implementation in interface definition Realization shown with dashed line, hollow arrow Like dependency plus generalization Why have this? Just factor out common functionality? Better pluggability, extensibility Tagged Values, Properties Every modeling element in UML has its set of properties Classes have: name, attributes, operations, etc. What if we want to add our own? (e.g. author?) Just add text in curly-brackets, with name=value, and put below the element name Note: These tell you something about the model, not about the final system to be built! Often used for code generation, version control, etc. Example: {abstract} classes instead of italics 2/7/00 G-3 2/7/00 G-32 Abstract Classes Constraints Implementation not provided for one or more operations So, a subclass must extend this to provide implementations How to show this in UML? Either italics for class name and operations Or, use {abstract} property by name An abstract class with no attributes and all abstract operations is effectively an interface But Java provides a direct implementation Conditions that restrict values, relationships, Can be free text or Object Constraint Langauge (OCL) (see textbook) Recommendation: Use sparingly! This example: from UML User Guide, p. 82 {secure} Portfolio BankAccount husband {or} Corporation Person gender : {female, male} 0.. 0.. wife {self.wife.gender = female and self.husband.gender = male} 2/7/00 G-33 2/7/00 G-34 Constraints and Semantics Example from UML User Guide, p. 88 A dependency and a constraint used Shows Manager must be one of Members of a Department One link (say, Jane-to- DeptA) is a subset of all links between Persons and DeptA Department {subset} member.. manager Person Derived Associations Often an association in a model be deduced from the existence of one or more other associations Do we show it? Is it redundant? Option: Draw it but mark it as derived Use a slash symbol / before name Can use slash in front of class attributes too! Course is taking teaches / teaches student Professor 2/7/00 G-35 Student 2/7/00 G-36 A - 6

Example: Ticket Sales Unused slides follow 2/7/00 G-37 2/7/00 G-38 Association Classes Association Class Example Recall that qualified associations really mean that the link between two objects has an attribute Often associations are first-class things They have a life-time, state, and maybe operations Just like objects! Association classes Same name as the association because... They represent the same thing! Company 0.. employer employee.. Person Job description : string datehired : Date salary : Money 2/7/00 G-39 2/7/00 G-40 World Cup Example World Cup Problem: Class Model We need a system to handle the World Cup. Teams represent countries and are made up of 22 players. Countries qualify from zones, where each zone is either a country or a group of countries. Each team plays a given number of games in a specific city. Referees are assigned to games. Hotel reservations are made in the city where the teams play. Represents Qualifying Unit Country Zone Represents 3 Referee 0 Team Hotel 2 Reservation 22 Player City 2 PlaysIn Plays at Game 4 3 Assignment 5 2/7/00 G-4 2/7/00 G-42 A - 7

Qualified Associations Qualified Association Examples: Equivalent to programming language idea of lookup, map, dictionary, associative array, etc. An object is associated with some number of other objects in a class How do we identify which one we want given that association? The qualifier documents attribute(s) used to identify which object The key for lookup Formally, these are attributes of the association Show Show sales perf: Date, seat: Number 0.. 0.. sales Ticket Ticket RepairDesk jobid: int 0.. ReturnedItem 2/7/00 G-43 2/7/00 G-44 Identifying Classes for Requirements Noun Extraction From textual descriptions or requirements or use cases, how do we get classes? Various techniques, and practice! Key Domain Abstractions: Real-world entities in your problem domain Noun identification Not often useful (but easy to describe) Remember: external view of the system for requirements Not system internals, not design components! Take some concise statement of the requirements Underline nouns or noun phrases that represent things These are candidate classes Object or not? Inside our system scope? An event, states, time-periods? An attribute of another object? Synonyms? Again, looking for things 2/7/00 G-45 2/7/00 G-46 Identifying Good Objects Actors and Classes Don t forget from earlier: attributes and operations are encapsulated in objects objects have a life-cycle Also, don t worry about user interface Think of user-commands as being encapsulated in the actors Consider: Collections, things in a container Roles Organizations In some diagrams, actors represented as class boxes With special stereotype above class name: <<actor>> UML allows special graphical symbol (e.g. a stick figure) to replace stereotyped classes See Richter, p. 53 2/7/00 G-47 2/7/00 G-48 A - 8