26
3 3 OBJECT MODELING OBJECT MODELING Object-Oriented Analysis and Design Object-Oriented Analysis and Design Source: OBJECT-ORIENTED MODELING AND DESIGN James Rumbaugh, Michael Blaha, William Premerlani, Frederick Eddy, William Lorensen PAUL VOUGNY - EPITA 2008 Source: OBJECT-ORIENTED MODELING AND DESIGN James Rumbaugh, Michael Blaha, William Premerlani, Frederick Eddy, William Lorensen PAUL VOUGNY - EPITA 2008

3 Object Modeling

Embed Size (px)

Citation preview

Page 1: 3 Object Modeling

33 OBJECTMODELINGOBJECTMODELING

Object-OrientedAnalysis and Design

Object-OrientedAnalysis and Design

Source: OBJECT-ORIENTED MODELING AND DESIGN

James Rumbaugh, Michael Blaha, William Premerlani, Frederick Eddy,

William Lorensen

PAUL VOUGNY - EPITA 2008

Source: OBJECT-ORIENTED MODELING AND DESIGN

James Rumbaugh, Michael Blaha, William Premerlani, Frederick Eddy,

William Lorensen

PAUL VOUGNY - EPITA 2008

Page 2: 3 Object Modeling

1. OBJECTS AND CLASSES

Two types of object diagrams :- class diagram- instance diagram

✘ CLASS DIAGRAM

Describes many possible instances of data.It describes object classes.

✘ INSTANCE DIAGRAM

Describes how a particular set of objects relate to each other.It describes object instances.

Page 3: 3 Object Modeling

(Person)Joe Smith

(Person)Mary Sharp (Person)Person

Class Objects

class diagram instance diagram

Personname : stringage : integer

(Person)Joe Smith24

(Person)Mary Sharp52

Class with Attributes Objects with Values

Personperson_ID : IDname : stringage : integer

Personname : stringage : integer

Wrong Correct

Do not explicitly list object identifiers

Page 4: 3 Object Modeling

Do not explicitly list object identifiers

A method (body) is the implentation of an operation (prototype, signature) for a class. Several methods may be refered by a generic operation. However, each method may be implemented by a different piece of code.

Personnameagechange_jobchange_address

Filefile_namesize_in_byteslast_updateprint

features of Person

Geometric Objectcolorpositionmove(delta : Vector)select(p : Point) : Booleanrotate(angle)

Class_Nameattribute_name : data_type = default_value...operation_name(argument_list) : result_type...

Operations

Object modeling

notation for classes

Page 5: 3 Object Modeling

2. LINK AND ASSOCIATIONS

✘ LINK : physical or conceptual connection between object instances. Instance of an association.

✘ ASSOCIATION : describes a group of links with common structure and common semantics. Inherently bidirectionnal. Often implemented as pointers from one object to another.

Pointer = attribute in one object that contains an explicit reference to another object.

WARNING: associations as pointers means not modeling them.

Each association in the class diagram corresponds to a set of links in the instance diagram, just as each class corresponds to a set of objects.

Page 6: 3 Object Modeling

Countryname

Cityname

Has_capital

(Country)Canada

(City)Ottawa

Has_capital

(Country)France

(City)Paris

Has_capital

(Country)Senegal

(City)Dakar

Has_capital

objectlink

object

association

class class

CLASSDIAGRAM

INSTANCEDIAGRAM

association and link names are

optionalleft to right if possible

One-to-one association

and links

Page 7: 3 Object Modeling

CAD:COMPUTER-AIDED

DESIGN

Linename

Pointname2+

CLASSDIAGRAM

INSTANCEDIAGRAM

(Line)L1

(Line)L2

(Line)L4

(Line)L5

(Line)L3

(Point)P1

(Point)P2

L3

L2

L1L4

L5

SAMPLE DATA

P2P1

Workstationconsole

Window zero-or-one multiplicity

multiplicity symbols:hollow ball (◦), solid ball (●) and "2+"

Many-to-many association

and links

Page 8: 3 Object Modeling

Projet

Person

Language

CLASSDIAGRAM

(Projet)accounting system

(Person)Mary

(Language)Cobol

INSTANCEDIAGRAM

(Projet)CAD Program

(Language)C

diamond

atomic unit

Many-to-many association

and links

Ternary association

and links

Page 9: 3 Object Modeling

3. ADVANCED LINK AND ASSOCIATION CONCEPTS

LINK ATTRIBUTES

File User

access permission

Accessible by

/etc/termcap/etc/termcap/usr/doe/.login

(read)(read-write)(read-write)

John DoeMary BrownJohn Doe

Link attribute for a many-to-many

association

Ternary association

and links

Page 10: 3 Object Modeling

salaryjob title

Works_forPerson

namesocial security no.address

Companynameaddress

Manages

boss

worker

performance rating

Link attributes for a one-to-many

association

Pitcher

Team

Year

winslosses

Harry EisenstatHarry EisenstatWillis HudinWillis HudinWillis HudinWillis Hudin

Cleveland IndiansDetroit TigersCleveland IndiansCleveland IndiansWashington SenatorsSt.Louis Brows

193919391939194019401940

W L

6 72 29 102 11 20 1

Link attributes

for a ternary association

Page 11: 3 Object Modeling

salaryjob title

Works_forCompany

nameaddress

Personnamesocial security no.address

Prefered form

Works_forCompany

nameaddress

Personnamesocial security no.addresssalaryjob title

Discouraged form

Link attributeversus

object attribute

Page 12: 3 Object Modeling

MODELING AN ASSOCIATION AS CLASS

User WorkstationAuthorized on

Authorizationpriorityprivilegesstart session

Directory

home directory

Modeling an association as a class

Page 13: 3 Object Modeling

ROLE NAMES

✘ A role is one end of an association.A binary association has two roles, each of which may have a role name.

✘ A role name is a name that uniquely identifies one end of an association.

Person CompanyWorks_for

employee employer

role

Joe DoeMary BrownJean Smith

employeeSimplexSimplexUnited Widgets

employer Role names for an

association

Use of role names is optional, but it is often easier and less confusing to assign role names instead of, or in addition to, association names.Role names are necessary for associations between two objects of the same class.

Page 14: 3 Object Modeling

Person Companyowner

authorized usercontents

containerRole names

for a directory hierarchy

ORDERING

Window ScreenVisible_on

{ordered}

Special kind of constraint

Ordered sets in an

association

Page 15: 3 Object Modeling

QUALIFICATION

A qualified association relates two object classes and a qualifier. The qualifier is a special attribute that reduces the effective multiplicity of an association. One-to-many and many-to-many associations may be qualified.

Directory file name File

Object class Qualifier Object class

Directory File

one-to-manyone-to-one

Qualification reduces the effective multiplicity of this association from one-to-many to one-to-one. A directory has many files, each with a file unique name.One way to find a file is to first find the directory and then traverse the file name link. For instance, a directory provides the context for a file name.

Page 16: 3 Object Modeling

Companyticker symbol Company

Stock exchange

Stock exchange

ticker symbolLists

Lists

Unqualified Qualified

Unqualified and

qualified association

Company office Personorganization officer

ABC widgetsABC widgetsABC widgetsABC widgetsABC widgetsXYZ candy

PresidentTreasurerDirectorDirectorDirectorPresident

Roger StickJoe EmbezzleJoe DoeJane DoeMoe BrownMoe Brown

Many-to-many qualification

Qualification partitions a set of related objects into disjoint subsets, but the subsets may contain more than one object.

Page 17: 3 Object Modeling

AGGREGATION

Aggregation is a tightly coupled form of association with some extra semantics.

Aggregation is:

✘ transitive: A part of B, B part of C ⇒ A part of C.✘ antisymetric: if A part of B, then B is not part of A.

Aggregation relationship ~ relating an assembly class to one component class. An assembly with many kinds of components corresponds to many aggregation relationships. We define each individual pairing as an aggregation so that we can specify the multiplicity of each component within the assembly. This definition emphasizes that aggregation is a special form of association.

Page 18: 3 Object Modeling

Document Paragraph Sentence

Aggregation

Aggregation is drawn like association, except a small diamond indicates the assembly end of the relationship.

The figure shows a portion of an object model for a word processing program. A document consists of many

paragraphs, each of which consists of many sentences.

Paragraphs cannot exist apart from a Document

Sentences cannot exist apart from a Paragraph

Microcomputer

Monitor System box Mouse Keyboard

Monitor System box Mouse Keyboard

MultilevelAggregation

Page 19: 3 Object Modeling

4. GENERALIZATION AND INHERITANCE

GENERAL CONCEPTS

Generalization and inheritance are powerful abstractions for sharing similarities among classes while preserving their differences.Each subclass is said to inherit the features of its superclass.

Generalization is sometimes called the IS A relationship because each instance of a subclass is an instance of the superclass as well. The terms ancestor and descendant refer to generalization of classes across multiple levels.

An instance of subclass is simultaneously an instance of all its ancestor classes. The state of an instance includes a value for every attribute of every ancestor class. Any operation on any ancestor class can be applied to an instance.

Monitor System box Mouse Keyboard

Page 20: 3 Object Modeling

Equipementnamemanufacturerweightcost

Pumpsuction pressuredischarge pressureflow rate

Heat exchangersurface areatube diametertube lenghttube pressureshell pressure

Tankvolumepressure

equipement type

. . .

Centrifugal pumpimpeller diameternumber of bladesaxis of rotation

Diaphragm pumpdiaphragm material

Plunger pumpplunger lenghtplunger diameternumber of cylinders

Spherical tankdiameter

Pressured tankdiameterheight

Floating roof tankdiameterheight

pump type

. . .tank type

. . .

discriminator(optional part of a generalization relationship)

Generalization

Specialization

Page 21: 3 Object Modeling

A discriminator is an attribute of enumeration type that indicates which property of an object is being abstracted by a particular generalization relationship.Only one property should be discriminated at once.Discriminator values are inherently in one-to-one correspondence with the subclasses of a generalization.

A multilevelinheritance hierarchy

with instances

(Diaphragm pump)name = P101manuf = Simplexweight = 100 kgcost = $5000suct pres = 1.1 atmdisch pres = 3.3 atmflow rate = 300 l/hrdia matl = Teflon

(Heat exchanger)name = E302manuf = Brownweight = 5000 kgcost = $20000surface area = 300 m2tube diameter = 2 cmtube lenght = 6 mtube pres = 15 atmshell pres = 1.7 atm

(Floating roof tank)name = T111manuf = Simplexweight = 10000 kgcost = $50000volume = 400000 literpressure = 1.1 atmdiameter = 8 mheight = 9 m

Page 22: 3 Object Modeling

Figurecolorcenter positionpen thicknesspen typemoveselectrotatedisplay

0 Dimensional 1 Dimensionalorientation

scale

2 Dimensionalorientationfille typescalefill

Point

display

Lineendpoints

display

Arcradiusstart anglearc angledisplay

Splinecontrol pts

display

Polygonnum of sides vertices

display

Circlediameter

displayrotate

dimensionality

Inheritance for graphic figures

In practise, whether or not a subclass is

"too deeply nested"depends upon judgment and the particular details

of a problem.

Page 23: 3 Object Modeling

USE OF GENERALIZATION

Generalization is a useful construct for both conceptual modeling and implementation programming community. The terms inheritance, generalization, and specialization all refer to aspects of the same idea and are often used interchangeably.

✘ Inheritance: mechanism of sharing attributes and operations using the generalization relationship.

✘ Generalization: derives from the fact that the superclass generates the subclasses.

✘ Specialization: refers to the fact that the subclasses refine or specialize the superclass.

Page 24: 3 Object Modeling

OVERRIDING FEATURES

✘ A subclass may override a superclass feature by defining a feature with the same name. The overriding feature (subclass) refines and replaces the overriden feature (superclass).

✘ An override should preserve attribute type, number, and type of arguments to an operation and operation return type. We should never override the signature, or form, of a feature.

✘ Tightening the type of an attribute or operation argument to be a subclass of the original type is a form of restriction and must be done with care.

Page 25: 3 Object Modeling

5. GROUPING CONSTRUCTS

MODULE

✘ A module is a logical construct for grouping classes, associations, and generalizations.

SHEET

✘ A sheet is the mechanism for breaking a large object model down into a series of pages. Each module consists of one or more sheets.

✘ Never more than one module per sheet.

✘ A sheet is just a notational convenience, not a logical construct.

✘ Multiple copies of the same class form the bridge for connecting sheets in an object model.

6. A SAMPLE OBJECT MODEL Windowx1x2y1y2displayundisplayraiselower

Page 26: 3 Object Modeling

6. A SAMPLE OBJECT MODEL Windowx1x2y1y2displayundisplayraiselower

Canvascx1cx2cy1cy2add-elementdelete-element

Panel

item nameScrollingwindow

x-offsety-offsetscroll

Shapecolorline width

Eventaction

Panel Item

xylabel

Text window

stringinsertdelete

Scrolling canvas

Linex1x2y1y2draw

Closed shape

fill colorfill pattern

Buttonstringdepressed

ChoiceItem

TextItem

max lengthcurrent string

Choice entrystringvalue

Ellipsexyabdraw

Polygon

draw

Pointxy

Object model of a

windowing system

window elementnotifyevent

keyboardevent

vertices{ordered}

currentchoice choices

{subset}