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.

Slides:



Advertisements
Similar presentations
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.
Advertisements

©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 8 Slide 1 System modeling 2.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Object-Oriented Analysis and Design
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 Class and Object Diagrams PRACTICAL OBJECT-ORIENTED DESIGN WITH.
2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.
Introduction To System Analysis and Design
1 Software Testing and Quality Assurance Lecture 12 - The Testing Perspective (Chapter 2, A Practical Guide to Testing Object-Oriented Software)
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 5: Restaurant.
1 SWE Introduction to Software Engineering Lecture 23 – Architectural Design (Chapter 13)
Design Patterns in Java Appendix D UML at a Glance Summary prepared by Kirk Scott 1.
Object Oriented System Development with VB .NET
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 1 CS 125 Introduction to Computers and Object- Oriented Programming.
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
Chapter Chapter 1 Introduction to Object-Oriented Programming and Software Development.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 Class and Object Diagrams PRACTICAL OBJECT-ORIENTED DESIGN WITH.
1 CS1001 Lecture Overview Object Oriented Design Object Oriented Design.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
Sharif University of Technology Session # 7.  Contents  Systems Analysis and Design  Planning the approach  Asking questions and collecting data 
Unified Modeling Language
Object-Oriented Analysis and Design
UML for Java Programmers Object Mentor, Inc. Copyright  by Object Mentor, Inc All Rights Reserved
Introduction To System Analysis and design
Object Oriented Software Development
Programming Languages and Paradigms Object-Oriented Programming.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Chapter 15 – Inheritance, Virtual Functions, and Polymorphism
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Object Orientation An Object oriented approach views systems and programs as a collection of interacting objects. An object is a thing in a computer system.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 1 Introduction to Object-Oriented Programming and.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
OBJECT AND CLASES: THE BASIC CONCEPTS Pertemuan 8 Matakuliah: Konsep object-oriented Tahun: 2009.
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
Copyright 2002 Prentice-Hall, Inc. Modern Systems Analysis and Design Third Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich Chapter 20 Object-Oriented.
Unified Modeling Language, Version 2.0
1. 2 Object-Oriented Concept Class & Object Object-Oriented Characteristics How does it work? Relationships Between Classes Development Tools Advantage.
Introduction To System 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 9: Interaction.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
Inheritance Building one object from another. Background Object-oriented programming is normally described has offering three capabilities Encapsulation:
CS3773 Software Engineering Lecture 04 UML Class Diagram.
Sommerville 2004,Mejia-Alvarez 2009Software Engineering, 7th edition. Chapter 8 Slide 1 System models.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 14 Slide 1 Object-oriented Design.
Basic OOP Concepts and Terms. In this class, we will cover: Objects and examples of different object types Classes and how they relate to objects Object.
BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class.
Appendix D UML at a Glance Summary prepared by Kirk Scott 1.
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
Object Oriented Analysis and Design Class and Object Diagrams.
Chapter 13 ATM Case Study Part 2: Implementing an Object-Oriented Design Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
1 Kyung Hee University Modeling with Objects Spring 2001.
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
Class Diagram Chapter 21 Applying UML and Patterns Craig Larman.
Introduction to Object-Oriented Programming Lesson 2.
1 Unified Modeling Language, Version 2.0 Chapter 2.
OOP Review CS 124.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
Fusion Design Overview Object Interaction Graph Visibility Graph Class Descriptions Inheritance Graphs Fusion: Design The overall goal of Design is to.
Class Diagram Lecture # 1. Class diagram A Class Diagram is a diagram describing the structure of a system shows the system's classes Attributes operations.
UML Fundamental Elements. Structural Elements Represent abstractions in our system. Elements that encapsulate the system's set of behaviors. Structural.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
CSCE 240 – Intro to Software Engineering Lecture 3.
A First Book of C++ Chapter 12 Extending Your Classes.
Chapter 3: Using Methods, Classes, and Objects
CompSci 230 Software Construction
Software Engineering Lecture #11.
Basic OOP Concepts and Terms
Presentation transcript:

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 with Objects

Practical Object-Oriented Design with UML 2e Slide 1/2 ©The McGraw-Hill Companies, 2004 The Object Model A general view of program structure shared by UML and object-oriented programming languages like Java and C++ Computation takes place in objects that: –store data and implement behaviour –are linked together in a network –communicate by sending messages –are described by classes

Practical Object-Oriented Design with UML 2e Slide 1/3 ©The McGraw-Hill Companies, 2004 UML and Code Because of the shared object model: –UML diagrams can easily be implemented –object-oriented programs can easily be documented in UML Reverse engineering: –creating a UML model for existing code –often useful in dealing with undocumented legacy systems

Practical Object-Oriented Design with UML 2e Slide 1/4 ©The McGraw-Hill Companies, 2004 Stock Control Example Keep track of parts in a warehouse and how they are used –parts have a part number, name and cost –the system must track individual parts –parts can be used to form assemblies –assemblies have a hierarchical structure Could be used for a variety of applications –e.g. find the cost of the materials in an assembly

Practical Object-Oriented Design with UML 2e Slide 1/5 ©The McGraw-Hill Companies, 2004 A Simple Part Class public class Part { private String name ; private long number ; private double cost ; public Part(String nm, long num, double cost) { name = nm ; // etc } public String getName( ) { return name; } // etc }

Practical Object-Oriented Design with UML 2e Slide 1/6 ©The McGraw-Hill Companies, 2004 The Part Class in UML A class is represented by a single UML icon PpPp

Practical Object-Oriented Design with UML 2e Slide 1/7 ©The McGraw-Hill Companies, 2004 UML Class Notation Class icons have three compartments –the first shows the class name –the second optionally shows attributes derived from its fields (data members) –the third optionally shows operations derived from its methods (member functions) constructors (and static methods) underlined Class features = attributes + operations –access levels: public (+) and private (-)

Practical Object-Oriented Design with UML 2e Slide 1/8 ©The McGraw-Hill Companies, 2004 Objects Objects are created at run-time as instances of classes: Part myScrew = new Part(“screw”, 28834, 0.02) ; Individual objects can be shown in UML:

Practical Object-Oriented Design with UML 2e Slide 1/9 ©The McGraw-Hill Companies, 2004 UML Object Notation Object icons have two compartments –the first shows the object and class names variable names can be used as object names the object name is optional the class name is preceded by a colon the names are always underlined –the second shows the actual data stored in the object, as attribute/value pairs this compartment is usually omitted

Practical Object-Oriented Design with UML 2e Slide 1/10 ©The McGraw-Hill Companies, 2004 Object Properties Objects have: –state: the data values held in the object –behaviour: the functionality it contains –identity: a distinguishing property of an object not an attribute value could be the object's address in memory –names: useful in modelling to refer to object Objects normally encapsulate their data

Practical Object-Oriented Design with UML 2e Slide 1/11 ©The McGraw-Hill Companies, 2004 Avoid Data Replication All parts of the same kind have the same attribute values (name, number, cost) –wasteful of resources –hard to maintain, eg if the cost changes Better to create a new class for shared data –call this a ‘catalogue entry’ –describes a type of part –each individual part described by one entry

Practical Object-Oriented Design with UML 2e Slide 1/12 ©The McGraw-Hill Companies, 2004 Parts and Catalogue Entries

Practical Object-Oriented Design with UML 2e Slide 1/13 ©The McGraw-Hill Companies, 2004 Implementation Catalogue entry class defines shared data Each part holds a reference to an entry public class Part { private CatalogueEntry entry ; public Part(CatalogueEntry e) { entry = e; } } When parts are created, an entry is given CatalogueEntry screw = new CatalogueEntry(“screw”,28834,0.02); Part s1 = new Part(screw) ; Part s2 = new Part(screw) ;

Practical Object-Oriented Design with UML 2e Slide 1/14 ©The McGraw-Hill Companies, 2004 Links References can be shown in UML as links –object name is name of variable –field name ‘entry’ used to label end of link

Practical Object-Oriented Design with UML 2e Slide 1/15 ©The McGraw-Hill Companies, 2004 Associations Data relationships between classes Links are instances of associations

Practical Object-Oriented Design with UML 2e Slide 1/16 ©The McGraw-Hill Companies, 2004 Properties of Associations Associations can have: –a name (not shown) –a rolename at each end derived from field name in code –a multiplicity at either end this specifies how many links there can be –an arrowhead at either end showing navigability derived from direction of reference in code

Practical Object-Oriented Design with UML 2e Slide 1/17 ©The McGraw-Hill Companies, 2004 UML Diagram Types Object diagrams show objects and links –this describes the run-time properties of a program Class diagrams show classes and associations –this shows the compile-time properties of a program –i.e. the logical structure of its source code

Practical Object-Oriented Design with UML 2e Slide 1/18 ©The McGraw-Hill Companies, 2004 Object Interaction Objects interact by method calls public class Part { private CatalogueEntry entry ; public double cost( ) { return entry.getCost(); } }... Part s1 = new Part(screw) ; double s1cost = s1.cost() ; Functionality is distributed among objects which must communicate

Practical Object-Oriented Design with UML 2e Slide 1/19 ©The McGraw-Hill Companies, 2004 Messages Object communication is shown in UML as message passing –a message corresponds to a method call –the class of the client object is not specified in this diagram

Practical Object-Oriented Design with UML 2e Slide 1/20 ©The McGraw-Hill Companies, 2004 Collaboration Diagrams Object diagrams with messages show collaborations –multiple messages can be shown on one diagram –return values are shown using the ‘:=’ notation

Practical Object-Oriented Design with UML 2e Slide 1/21 ©The McGraw-Hill Companies, 2004 Assemblies Assemblies contain parts –Links show which assembly a part belongs to

Practical Object-Oriented Design with UML 2e Slide 1/22 ©The McGraw-Hill Companies, 2004 Implementing Assemblies Assemblies could be implemented using a data structure to hold references to parts public class Assembly { private Vector parts = new Vector() ; public void add(Part p) { parts.addElement(p) ; } These links are instances of a new association

Practical Object-Oriented Design with UML 2e Slide 1/23 ©The McGraw-Hill Companies, 2004 The 'Contains' Association ‘Contains’ is the association name –“an assembly contains parts” ‘parts’ is the rolename Assemblies can contain zero or more parts –this is documented by the ‘parts’ multiplicity

Practical Object-Oriented Design with UML 2e Slide 1/24 ©The McGraw-Hill Companies, 2004 Subassemblies

Practical Object-Oriented Design with UML 2e Slide 1/25 ©The McGraw-Hill Companies, 2004 Polymorphism This requires assemblies to hold a mix of pointers to parts and (sub)assemblies Inheritance is often used to implement this: public abstract class Component {... } public class Part extends Component {... } public class Assembly extends Component { private Vector components = new Vector() ; public void addComponent(Component c) { components.addElement(c) ; }

Practical Object-Oriented Design with UML 2e Slide 1/26 ©The McGraw-Hill Companies, 2004 Generalization Java’s ‘extends’ relationship is represented by generalization in UML –Also called specialization if viewed ‘downwards’

Practical Object-Oriented Design with UML 2e Slide 1/27 ©The McGraw-Hill Companies, 2004 Properties of Generalization Generalization is not an association: –does not give rise to links between objects –usually unlabelled –never has multiplicity annotations Explained by ‘substitutability’: –an instance of a subclass can be used wherever an instance of a superclass is expected –similar to ‘reference conversions’ in Java

Practical Object-Oriented Design with UML 2e Slide 1/28 ©The McGraw-Hill Companies, 2004 A Polymorphic Association Assemblies contain Components: –instances of ‘Contains’ can link assemblies to instances of both Component subclasses –the Component class is abstract (no instances)

Practical Object-Oriented Design with UML 2e Slide 1/29 ©The McGraw-Hill Companies, 2004 The Cost of an Assembly Add up the cost of all the components

Practical Object-Oriented Design with UML 2e Slide 1/30 ©The McGraw-Hill Companies, 2004 Dynamic Binding Both ‘Part’ and ‘Assembly’ classes must implement a ‘cost’ method An assembly sends the ‘cost’ message to all its components The run-time system checks the type of the message receiver and invokes the correct method

Practical Object-Oriented Design with UML 2e Slide 1/31 ©The McGraw-Hill Companies, 2004 Applicability of Object Model Some classes inspired by real-world objects Real-world doesn’t necessarily provide a good software design –e.g. data replication in the original ‘Part’ class Object-orientation better understood as an effective approach to software architecture