Class Diagram. A class diagram describes the classes and the association (static relationship) between these classes ( 描述系統中物件 的 type(class) ,以及這些 class.

Slides:



Advertisements
Similar presentations
214 CONCEPTUAL DESIGN: UML CLASS DIAGRAM RELATIONSHIPS.
Advertisements

Stereotypes Stereotypes provide the capability to create a new kind of modeling element. –They can be used to classify or mark modeling elements. –A type.
CS 340 UML Class Diagrams. A model is an abstraction of a system, specifying the modeled system from a certain viewpoint and at a certain level of abstraction.
Inheritance Inheritance Reserved word protected Reserved word super
UML Class Diagram. UML Class Diagrams2 Agenda What is a Class Diagram? Essential Elements of a UML Class Diagram Tips.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
UML – Class Diagrams.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
Chapter 14 (Web): Object-Oriented Data Modeling
What is UML? A modeling language standardized by the OMG (Object Management Group), and widely used in OO analysis and design A modeling language is a.
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
- 1 - © Houman Younessi 2010 MGMT Advanced Systems Analysis and Design A dvanced S ystems A nalysis and D esign Fall 2010 Convener: Houman Younessi.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
IMSE 11 - UML Class Diagrams
7M822 UML Class Diagrams advanced concepts 15 September 2008.
7M822 UML Class Diagrams advanced concepts 14 October 2010.
Inheritance and Polymorphism CS351 – Programming Paradigms.
PRJ566: PROJECT PLANNING AND MANAGEMENT Class Diagrams.
Chapter 14: Object-Oriented Data Modeling
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
The Unified Modeling Language (UML) Class Diagrams.
Object-Oriented Analysis and Design
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
Class Diagram.
Software Construction Lecture 5 Class Diagrams. Agenda 2  Topics:  Examples of class diagrams  Navigation, visibility, named associations, and multiplicity.
What is inheritance? It is the ability to create a new class from an existing class.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
Distributed Java Programming Distributed Java Programming Class #2 August 22, 2002.
A little bit of UML Csaba Veres. UML A de facto standard for OO analysis and design Many components class diagrams use cases interaction diagrams...
Unit 1 INTRODUCTION TO MODELING AND CLASS MODEL Ref : L7-UML.PDF.
Chapter 16 Applying UML and Patterns Craig Larman
1 Class Diagrams: Advanced Concepts. 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are the most commonly used diagrams.
UML Class Diagram Trisha Cummings. What we will be covering What is a Class Diagram? Essential Elements of a UML Class Diagram UML Packages Logical Distribution.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Advanced UML Class Diagrams.
NJIT UML Class Diagrams Chapter 16 Applying UML and Patterns Craig Larman.
UML The Unified Modeling Language A Practical Introduction Al-Ayham Saleh Aleppo University
Object-Oriented Data Modeling
Design Model Lecture p6 T120B pavasario sem.
Relationships Relationships between objects and between classes.
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
Object Oriented Analysis and Design Class and Object Diagrams.
1 Class Diagrams. 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are for visualizing, specifying and documenting.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
UML Class Diagram. A class diagram shows 1.Classes 2.The relationships between them.
1 Tony Busker Object Oriented Software Development 4.
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
Class diagrams Terézia Mézešová.
Chapter 16: UML Class Diagrams
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
ITEC0724 Modern Related Technology on Mobile Devices Lecture Notes #2 1.
Kyung Hee University Class Diagramming Notation OOSD 담당조교 석사과정 이정환.
Class Diagrams Revisited. Parameterized Classes Parameterized Classes - are used to represent relationships between templates.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Unified Modeling Language (UML)
Object-Oriented Modeling
UML-Class Diagrams. UML-Class Diagrams Order placement problem A Company has two types of customers, corporate customers and personal customers. All.
Business System Development
A Review or Brief Introduction
EKT472: Object Oriented Programming
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
UML Class & Object Diagram II
Introduction to UML Introduction to UML Shiyuan Jin September,23,2002
Object Oriented Analysis and Design
UML Class Diagram.
Unified Modelling Language
Class Diagrams Class diagram is basically a graphical representation of the static view of the system and represents different aspects of the application.
Basic OOP Concepts and Terms
Object Oriented System Design Class Diagrams
Presentation transcript:

Class Diagram

A class diagram describes the classes and the association (static relationship) between these classes ( 描述系統中物件 的 type(class) ,以及這些 class 的靜態關連.) A class diagram describes the classes and the association (static relationship) between these classes ( 描述系統中物件 的 type(class) ,以及這些 class 的靜態關連.) association (for example, a customer may rent a number of videos) association (for example, a customer may rent a number of videos) subtypes ( a nurse is a kind of person) subtypes ( a nurse is a kind of person)

Order dateReceived isPrepaid number:string price:Money dispatch() close Order Line Quantity:integer price:Money isSatisfied:bool Customer name address creditRating():String Corporate customer contractName creditRating creditLimit remind() billForMonth(int) Personal Customer CreditCard# Employee Product *1 1 * 1* line items {if Order.customer.creditRati ng is “poor”, then Order.isPrepaid must be true } * 0..1 {creditRating()= “poor”} sale rep Multiplicity:mandatory Multiplicity:many-valued association constraints attributesgeneralization class Multiplicty:optional Role name

navigability See next fig See next fig In specification model, an Order has a responsibility to tell you which Customer it is for, but not conversely In specification model, an Order has a responsibility to tell you which Customer it is for, but not conversely In implementation diagram, this would indicate that Order contains a pointer to Customer In implementation diagram, this would indicate that Order contains a pointer to Customer

Order dateReceived isPrepaid number:string price:Money dispatch() close Order Line Quantity:integer price:Money isSatisfied:bool Customer name address creditRating():String Corporate customer contractName creditRating creditLimit remind() billForMonth(int) Personal Customer CreditCard# Employee Product *1 1 * 1* line items {if Order.customer.creditRati ng is “poor”, then Order.isPrepaid must be true } * 0..1 {creditRating()= “poor”} sale rep navigability

Generalization Generalization (In OOP term, is inheritance) Generalization (In OOP term, is inheritance) see personal and corporate customers see personal and corporate customers Using polymorphism, the corporate customer may respond to certain commands differently from another customer Using polymorphism, the corporate customer may respond to certain commands differently from another customer

Operations Most obviously correspond to the methods on a class Most obviously correspond to the methods on a class UML syntax is UML syntax is visibility name (parameter list): return-type-expression {property string} visibility name (parameter list): return-type-expression {property string}

Class Diagrams: Advanced Concepts

Object Diagram A snapshot of the objects in a system at a point in time Often called instance diagram Let’s see the class diagram first Party location Organization Person * children 1 parent

Object Diagram engineering:Organization location=“boston” tools:Organization location=“Chicago” apps:Organization location=“Saba” John:Person location=“Champaign” Don:Person location=“Champaign” parent This is associations not generalization or inheritance this is object not class

Class Scope Operations and Attributes Order getNumber getNextNewNumber instance scope class scope Class scope is equivalent to static members in C++

Multiple and Dynamic Classification Female Male Patient Physio- therapist Nurse Doctor Family Doctor Surgeon sex {complete} role patient Discriminator

Multiple Classification Don’t confuse with multiple inheritance. Don’t confuse with multiple inheritance. You should make it clear which combinations are legal by using a discriminator You should make it clear which combinations are legal by using a discriminator

Dynamic Classification Person Male Female Salesman Engineer Manager Job > sex {complete}

Dynamic Classification allow object to change type within the subtyping structure allow object to change type within the subtyping structure useful for conceptual modeling useful for conceptual modeling How to implement it? See Fowler 1997 How to implement it? See Fowler 1997

Aggregation and Composition Aggregation is the part-of relationship Aggregation is the part-of relationship difficult things – what is the difference between aggregation and association? difficult things – what is the difference between aggregation and association? It is vague and inconsistent It is vague and inconsistent Anyway, UML decide to include aggregation and a stronger variety of aggregation called composition Anyway, UML decide to include aggregation and a stronger variety of aggregation called composition

Point Style color isFilled Polygon Circle radius {ordered} 3..* * 1 1 * 1 Composition aggregation

Composition With composition, the part object may belong to only one whole; further, the parts are usually expected to live and die with the whole With composition, the part object may belong to only one whole; further, the parts are usually expected to live and die with the whole deletion of the whole is considered to cascade to the part deletion of the whole is considered to cascade to the part In previous graph, deleting a polygon would caused its associated Points to be deleted, but not the associated Style. In previous graph, deleting a polygon would caused its associated Points to be deleted, but not the associated Style.

Alternative Notation for Composition CirclePolygon Point 1 {ordered} 3..* Style 1 1 **

Derived Associations and Attributes Derived Associations and derived attributes can be calculated from other associations and attributes. Derived Associations and derived attributes can be calculated from other associations and attributes. for example, an age attribute of a Person can be derived if you know that person’s birthday. for example, an age attribute of a Person can be derived if you know that person’s birthday.

Account /balance:Money Entry amount:Money Summary Account Detail Account /entries* {balance= sum of amounts of entries} Components {hierarchy} * 0..1 Derived attribute Derived Association 1

Note Entry objects are attached to detail Accounts Entry objects are attached to detail Accounts The balance of an Account is calculated as the sum of Entry accounts The balance of an Account is calculated as the sum of Entry accounts A Summary Account’s entries are the entries of its components determined recursively A Summary Account’s entries are the entries of its components determined recursively

Interfaces and Abstract Classes Programming language that use a single construct, the class, which contains both interface and implementation. Programming language that use a single construct, the class, which contains both interface and implementation. When you subclass, you inherit both. When you subclass, you inherit both. A pure interface, as in Java, is a class with no implementation and, therefore, has operation declarations but no method bodies and no fields. A pure interface, as in Java, is a class with no implementation and, therefore, has operation declarations but no method bodies and no fields.

For example interface Stack { boolean Push(Object); Object Pop(); } Class MyStack implements Stack boolean Push(Objects) { …….. } Object Pop() { …….. return xxxx ; } Somewhere in initialization Stack S = new MyStack() ; Somewhere in the code S.push(a); S.push(b); S.pop(a); S.pop(b);

text Editor Window {abstract} toFront() toBack() Win98 Window toFront() toBack() X11 Window toFront() toBack() Mac Window toFront() toBack() Dependency

InputStream DataInputStream > DataInput OrderReader Realization generalization dependency

Abstract Class and Interface two are similar two are similar abstract class allows you to add implementation of some of the methods abstract class allows you to add implementation of some of the methods an interface forces you to defer definition of all methods an interface forces you to defer definition of all methods

Classification and Generalization People often talk subtyping as the “is a” relationship People often talk subtyping as the “is a” relationship beware of that way of thinking beware of that way of thinking for example 1. Shep is a border Collie 2. A border Collie is a Dog 3. Dogs are animals 4. A border Collie is a Breed ( 品種 ) 5. Dog is a Species ( 物種) for example 1. Shep is a border Collie 2. A border Collie is a Dog 3. Dogs are animals 4. A border Collie is a Breed ( 品種 ) 5. Dog is a Species ( 物種) if you try combination 2 and 5 “A border Collie is a Species”. This is not good if you try combination 2 and 5 “A border Collie is a Species”. This is not good The reasons? The reasons? some are classification and some are generalization some are classification and some are generalization Generalization is transitive and classification is not Generalization is transitive and classification is not “Dog are a kind of animals” is better “Dog are a kind of animals” is better

Qualified Associations equivalent to associative arrays, maps, and dictionaries equivalent to associative arrays, maps, and dictionaries an example, there maybe one Order Line for each instance of Product an example, there maybe one Order Line for each instance of Product Conceptually, you cannot have two Order Lines within an Order for the same product Conceptually, you cannot have two Order Lines within an Order for the same product Order Order Line amount:Number product 0..1 line item

Qualified association would imply an interface like class Order { public OrderLine getLineItem (Product aProduct);; public void addLineItem (Number amount, Product forProduct); }

Order Order Line amount:Number product line item You can have multiple OrderLines per Product but access to the Line Items is still indexed by Product You can have multiple OrderLines per Product but access to the Line Items is still indexed by Product use an associative array or similar data structure to hold the order lines use an associative array or similar data structure to hold the order lines Class Order { Class Order { private Map _lineItems ; private Map _lineItems ; *

Association Class Association class allow you to add attributes, operations, and other features to association Association class allow you to add attributes, operations, and other features to association Person Company Employment period:dateRange employer* association class 0..1

A person may work for a single company A person may work for a single company We need to keep information about the period of time that each employee works for each Company We need to keep information about the period of time that each employee works for each Company You can redraw: make Employment a full class in its own right You can redraw: make Employment a full class in its own right Employment period:dateRange PersonCompany 10..1* 1 /employer 0..1*

Parameterized Class Several language, noticeably C++, have the notion of a parameterized class or template Several language, noticeably C++, have the notion of a parameterized class or template ex class set { void insert (T newElement); void remove(T anElement); … … Set employSet ; ex class set { void insert (T newElement); void remove(T anElement); … … Set employSet ;

A define a parameterized class in UML Set insert(T) remove(T) T template Parameter template class

A use of a parameterized class Set insert(T) remove(T) T EmployeeSet > Bound Element

Visibility C++ C++ A public member is visible anywhere in the program and may be called by any object within the system A public member is visible anywhere in the program and may be called by any object within the system A private member may be used only by the class that defines it A private member may be used only by the class that defines it A protected member may be used only by (a) the class that defines it or (b) a subclass of that class A protected member may be used only by (a) the class that defines it or (b) a subclass of that class In Java In Java a protected member may be accessed by subclasses but also by any other class in the same package as the owning class a protected member may be accessed by subclasses but also by any other class in the same package as the owning class C++ C++ one C++ method or class can be made a friend of a class. A friend has complete access to all members of a class one C++ method or class can be made a friend of a class. A friend has complete access to all members of a class