Object Oriented Analysis and Design Using the UML
Object Oriented Analysis and Design Using the UML Introduction to Object Orientation OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 1
Objectives: Introduction to Object Orientation w Understand the basic principles of object orientation w Understand the basic concepts and terms of object orientation and the associated UML notation w Appreciate the strengths of object orientation w Understand some basic UML modeling mechanisms OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 2
Introduction to Object Orientation Topics w 1. w 2. w 3. w 4. Basic Principles of Object Orientation Basic Concepts of Object Orientation Strengths of Object Orientation General UML Modeling Mechanisms OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 3
1. Basic Principles of Object Orientation OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 4 Hierarchy Modularity Encapsulation Abstraction Object Orientation
What is Abstraction? Salesperson Not saying which salesperson – just a salesperson in general!!! Product Customer Manages Complexity OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 5
What is Encapsulation? w Hide implementation from clients § Clients depend on interface – only! § Clients do not need to know ‘how’ the server operates or provides the services! How does an object encapsulate? What does it encapsulate? DISCUSS!!!!! Improves Resiliency OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 6
What is Modularity? w The breaking up of something complex into manageable pieces Order Entry Order Processing System Order Fulfillment Billing Manages Complexity OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 7
What is Hierarchy? Asset w Levels of abstraction Increasing abstraction Security Bank. Account Savings Checking Decreasing abstraction Stock Bond Elements at the same level of the hierarchy should be at the same level of abstraction OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 8 Real. Estate
Introduction to Object Orientation Topics w Basic Principles of Object Orientation w Basic Concepts of Object Orientation w Strengths of Object Orientation w General UML Modeling Mechanisms OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 9
2. Basic Concepts of Object Orientation w Object w Class w Attribute w Operation w Interface (Polymorphism) w Component w Package w Subsystem w Relationships OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 10
A More Formal Definition w An object is a concept, abstraction, or thing with sharp boundaries and meaning for an application w An object is something that has: § State § Behavior § Identity OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 11
Representing Objects w An object is represented as rectangles with underlined names : Professor a + b = 10 Professor. Clark Class Name Only Professor. Clark : Professor Clark Object Name Only Class and Object Name OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved (stay tuned for classes) 12
Basic Concepts of Object Orientation w Object w Class w Attribute w Operation w Interface (Polymorphism) w Component w Package w Subsystem w Relationships OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 13
What is a Class? w A class is a description of a group of objects with common properties (attributes), behavior (operations), relationships, and semantics w A class is an ‘abstraction’ of objects…. § An object is an instance of a class w A class is an abstraction in that it: § Emphasizes relevant characteristics § Suppresses other characteristics OO Principle: Abstraction OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 14
Representing Classes w A class is represented using a compartmented rectangle a + b = 10 Professor Clark OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 15
Class Compartments w A class is comprised of three sections § The first section contains the class name § The second section shows the structure (attributes) § The third section shows the behavior (operations) Class Name Attributes Operations OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved Professor name emp. ID create( ) save( ) delete( ) change( ) 16
The Relationship Between Classes and Objects w A class is an abstract definition of an object § It defines the structure and behavior of each object in the class § It serves as a template for creating objects Class Objects Professor Smith Professor Mellon Professor Jones OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 17
Basic Concepts of Object Orientation w Object w Class w Attribute w Operation w Interface (Polymorphism) w Component w Package w Subsystem w Relationships OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 18
What is an Attribute? Object Class Attribute Value : Course. Offering number = 101 start. Time = 900 end. Time = 1100 number start. Time end. Time : Course. Offering number = 104 start. Time = 1300 end. Time = 1500 OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 19
Basic Concepts of Object Orientation w Object w Class w Attribute w Operation w Interface (Polymorphism) w Component w Package w Subsystem w Relationships OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 20
What is an Operation? Course. Offering Class Operation OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved add. Student delete. Student get. Start. Time get. End. Time 21
Basic Concepts of Object Orientation w Object w Class w Attribute w Operation w Interface (Polymorphism) w Component w Package w Subsystem w Relationships OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 22
What is Polymorphism? w The ability to hide many different implementations behind a single interface Manufacturer A Manufacturer B OO Principle: Encapsulation OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 23 Manufacturer C
What is an Interface? w Interfaces formalize polymorphism w Interfaces support “plug-and-play” architectures Tube <<interface>> Shape Pyramid Draw Move Scale Rotate abstract methods Cube Realization relationship. Tube, Pyramid, and Cube ‘implement’ the interface! OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved (stay tuned for realization relationships) 24
Interface Representations Tube Elided/Iconic Representation (“lollipop”) Pyramid Shape Canonical (Class/Stereotype) Representation Cube Tube <<interface>> Shape Pyramid Draw Move Scale Rotate OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved Cube 25 (stay tuned for realization relationships)
Basic Concepts of Object Orientation w Object w Class w Attribute w Operation w Interface (Polymorphism) w Component w Package w Subsystem w Relationships OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 26
What is a Component? w A non-trivial, nearly independent, and replaceable part of a system that fulfills a clear function in the context of a welldefined architecture w A component may be § A source code component § A run time component or § An executable component Source File Name OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved <<EXE>> Executable Name 27 OO Principle: Encapsulation Component Interface <<DLL>> Component Name
Basic Concepts of Object Orientation w Object w Class w Attribute w Operation w Interface (Polymorphism) w Component w Package w Subsystem w Relationships OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 28
What is a Package? w A package is a general purpose mechanism for organizing like elements into groups w A model element which can contain other model elements Package Name OO Principle: Modularity w Uses § Organize the model under development § A unit of configuration management OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 29
Basic Concepts of Object Orientation w Object w Class w Attribute w Operation w Interface (Polymorphism) w Component w Package w Subsystem w Relationships OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 30
What is a Subsystem? w A combination of a package (can contain other model elements) and a class (has behavior) w Realizes one or more interfaces which define its behavior w Interface is an abstract class. Subsystem implements (realizes) the interface (interfaces)… Realization <<subsystem>> Subsystem Name Interface Subsystem Interface OO Principles: Encapsulation and Modularity (stay tuned for realization relationship) OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 31
Subsystems and Components w Components are the physical realization of an abstraction in the design w Subsystems can be used to represent the component in the design Design Model Implementation Model <<subsystem>> Component Name Component Interface Component Name OO Principles: Encapsulation and Modularity OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 32
Basic Concepts of Object Orientation w Object w Class w Attribute w Operation w Interface (Polymorphism) w Component w Package w Subsystem w Relationships OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 33
Relationships w Association § Aggregation § Composition w Dependency w Generalization w Realization OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 34
Relationships: Association w Models a semantic connection among classes Association Name Add these descriptions via Open Specification in Rose Professor University Works for Association Class Role Names University Professor Employee OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 35 Employer
Relationships: Aggregation w A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts Whole Part Schedule Student Aggregation OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved This is sometimes called a ‘has_a’ relationship 36
Relationships: Composition w A form of aggregation with strong ownership and coincident lifetimes § The parts cannot survive the whole/aggregate Part Whole Schedule Student Aggregation OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 37
Association: Multiplicity and Navigation w Multiplicity defines how many objects participate in a relationships § The number of instances (that is, ‘objects’) of one class related to ONE instance of another class § Specified for each end of the association w Associations and aggregations are bidirectional by default, but it is often desirable to restrict navigation to one direction § If navigation is restricted, an arrowhead is added to indicate the direction of the navigation OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 38
Association: Multiplicity w Unspecified w Exactly one 1 w Zero or more (many, unlimited) 0. . * * w One or more w Zero or one w Specified range w Multiple, disjoint ranges OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 39 1. . * 0. . 1 2. . 4 2, 4. . 6
Example: Multiplicity and Navigation Multiplicity Student 1 0. . * Schedule Navigation A student has zero or more schedules. (Multiplicity) Note: Aggregation: ‘has_a’ and whole-part relationship. (type of Associa OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 40
Relationships: Dependency w A relationship between two model elements where a change in one may cause a change in the other w Non-structural, “using” relationship w Can actually say the Client ‘uses’ the Supplier. Client Class Package Supplier OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved Supplier Client Dependency relationship Client. Package Component Supplier. Package 41 Dependency relationship
Relationships: Generalization w A relationship among classes where one class shares the structure and/or behavior of one or more classes w Defines a hierarchy of abstractions in which a subclass inherits from one or more superclasses § Single inheritance § Multiple inheritance w Generalization is an “is-a-kind of” relationship, or simply, “is_a” relationship. OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 42
Example: Single Inheritance w One class inherits from another Ancestor Account balance name number Superclass (parent) Withdraw() Create. Statement() Generalization Relationship Subclasses Checking Savings Withdraw() Get. Interest() Withdraw() Descendents OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 43 Subclasses inherit both attributes and methods from base (parent) class.
Example: Multiple Inheritance w A class can inherit from several other classes Flying. Thing Animal multiple inheritance Airplane Helicopter Bird Wolf Horse Use multiple inheritance only when needed, and always with caution ! OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 44
What Gets Inherited? w A subclass inherits parent’s attributes, operations, and relationships w A subclass may: § Add additional attributes, operations, relationships § Redefine inherited operations (use caution!) w Common attributes, operations, and/or relationships are shown at the highest applicable level in the hierarchy Inheritance leverages the similarities among classes OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 45
Example: What Gets Inherited Ground. Vehicle Superclass (parent) weight license. Number owner 0. . * Person 1 register( ) generalization Subclass Truck Car size tonnage get. Tax( ) OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 46 Trailer
Relationships: Realization w One classifier serves as the contract that the other classifier agrees to carry out w Found between: § Interfaces and the classifiers that realize them Subsystem Interface Canonical form Use Case OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved Elided form Use-Case Realization 47
Introduction to Object Orientation Topics w Basic Principles of Object Orientation w Basic Concepts of Object Orientation w Strengths of Object Orientation w General UML Modeling Mechanisms OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 49
4. Stereotypes w Classify and extend the UML notational elements w Define a new model element in terms of another model element w May be applied to all modeling elements w Represented with name in guillemets or as a different icon <<boundary>> My. Boundary. Class OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 50
Notes w A Note can be added to any UML element w Notes may be added to add more information to the diagram w It is a ‘dog eared’ rectangle w The note may be anchored to an element with a dashed line There can be up to one Maintain. Schedule. Form per user session. Maintain. Schedule. Form OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 51
Tagged Values w Extensions of the properties, or specific attributes, of a UML element w Some properties are defined by UML § Persistence § Location (e. g. , client, server) w Properties can be created by UML modelers for any purpose Persistent. Class {persistence} OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved an. Object : Class. A {location=server} 52
Constraints w Supports the addition of new rules or modification of existing rules Professor Member 1 1. . * Department Head 1 Department {subset} 1 This notation is used to capture two relationships between Professor-type object and Department-type objects; where one relationship is a subset of another…. Shows how UML can be tailored to correctly modeling exact relationships…. OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 53
Review: Introduction to Object Orientation w What are the four basic principles of object orientation? § Provide a brief description of each. w What is an Object and what is a Class? § What is the difference between them? w What is an Attribute? w What is an Operation? w What is an Interface? w What is Polymorphism? w What is a Component? OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 54 (continued)
Review: Introduction to Object Orientation (cont. ) w What is a Package? w What is Subsystem? § How does it relate to a Component? § How does it relate to a package? § How does it relate to a class? w Name the four basic UML relationships and describe each. w Describe the strengths of object orientation. w Name and describe some general UML mechanisms. w What are stereotypes? § Name some common uses of stereotypes. OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 55
- Slides: 54