Object Oriented Analysis and Design Using the UML

Object Oriented Analysis and Design Using the UML Introduction to Object Orientation (abbreviated!) 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

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 Know This. 3 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 4

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 5

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 6

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 7 Real. Estate

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 8

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 w Know This. OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 9

Representing Objects – the beginnings… w An object is represented as a rectangle with underlined name (no class name shown here) : Professor (unnamed object) 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) 10

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 OO Principle: Abstraction OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 11

Representing Classes w A class is represented using a compartmented rectangle § (note: no underlining) a + b = 10 Professor Clark OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 12

Class Compartments – a bit more development 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( ) 13

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 14

What is an Attribute? Object Class Attribute Course. Offering Specific attribute values for different objects number start. Time end. Time : Course. Offering number = 101 start. Time = 900 end. Time = 1100 : 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 15

What is an Operation? (very general form here…) Course. Offering Class Operation add. Student delete. Student get. Start. Time get. End. Time Really need to show more, but here, this is sufficient. OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 16

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 17 OO Principle: Encapsulation Component Interface <<DLL>> Component Name

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 w Think: in the Java API, similar classes are found in ‘packages’ that we may import, etc. Package Name w Uses § Organize the model under development § A unit of configuration management OO Principle: Modularity Know This § Think: Math class. (contains math classes such as cos() ) OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 18

Example for Data Structures Class: w Think IO package you imported. w Inside this package are many (often) unrelated classes. § § File. Reader Buffered. Reader File. Writer Printer. Writer, etc. w To USE any of these classes, we merely create an object of them and proceed – independently of any other classes. w To USE any of these classes in the package, we go directly to the class, instantiate the class, and use the methods in the objects. OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 19

What is a Subsystem? w A combination of a package (contains other model elements) and a class (has behaviors) w A subsystem: realizes one or more interfaces which define its behavior w Interface is an abstract class. Subsystems implement (realize) the interface(s)… Realization <<subsystem>> Subsystem Name Interface Subsystem Interface OO Principles: Encapsulation and Modularity Know This. OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 20 (stay tuned for realization relationship)

Example of Subsystems Realization <<subsystem>> Subsystem Name Interface Subsystem might be Accounts. Receivable, Accounts. Payable, Billing, That is, a major hunk of functionality. BUT, a client of the subsystem does NOT have access to the individual Classes like in a Package. Rather, a client must go through the public Interface to the subsystem, which contains the signatures of the services provided within the subsystem. The contents of the subsystem are NOT directly accesses; They are protected; Only the services shown in the interface are made available to clients. OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 21

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 22

Relationships: Association w Models a semantic connection among classes Association Name 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 23 Employer

Relationships: Aggregation (simple aggregate) w A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts Whole Part Schedule Student Know This OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved Aggregation – sometimes called ‘simple aggregation. ’ This is sometimes called a ‘has_a’ relationship 24

Relationships: Composition w A form of aggregation with strong ownership and coincident lifetimes § The parts cannot survive the whole/aggregate Part Whole Schedule Student Know This OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved Aggregation This one is called ‘composition. ’ 25

Association: Multiplicity and Navigation w Multiplicity defines how many objects participate in a relationship § Multiplicity is a Structural Relationship! § The number of instances (that is, ‘objects’) of one class related to ONE instance of another class (examples ahead) § Specified for each end of the association w Associations and aggregations are bi -directional 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 26

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 27 1. . * 0. . 1 2. . 4 2, 4. . 6

Example: Multiplicity and Navigation Multiplicity Student 1 0. . * Schedule Navigation Note: A student has zero or more schedules. (Multiplicity) Note: Aggregation: ‘has_a’ (whole-part relationship). OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 28

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” (or “communicates”) relationship § (non-structural: no numbers of one kind related to another kind…) w Can actually say the Client ‘uses’ the Supplier. Know This 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 29 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 w Generalization is a “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 30

Example: Single Inheritance w One class inherits from another Ancestor Account balance name number Superclass (parent) Withdraw() Create. Statement() Generalization Relationship Savings Checking Subclasses Get. Interest() Withdraw() Descendents OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 31 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 32

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 33

Example: What Gets Inherited (note form of arrow) Ground. Vehicle Superclass (parent) weight license. Number owner 0. . * Person 1 register( ) generalization Subclass Truck Car size tonnage get. Tax( ) What about a ‘register()’ in Car? OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 34 Trailer

Relationships: Realization (note form of arrow) 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 35

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 37

4. Stereotypes w Classify/extend 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 38

Notes w A Note can be added to any UML element § The class diagram is the one most often extended… w Notes may be added to add more info to diagram § It is a ‘dog eared’ rectangle § 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 39

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} 40

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 objects 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 41

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 42 (continued)

Review: Introduction to Object Orientation (cont. ) w What is a Package? Know This 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 43
- Slides: 42