34
Prepared By:Mitali sonar

Prepared By:Mitali sonarsvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch_3_class_model.pdf · OOAD It focuses on ... association in which an attribute called Qualifier disambiguates

Embed Size (px)

Citation preview

Prepared By:Mitali

sonar

OOAD

It focuses on objects where system is

broken down in terms of the objects that

exist within it.

Functions (behaviour) and data (state)

relating to a single object are self-

contained or encapsulated in one place.

2

OBJECTS

Object is an abstraction of something in a problem

domain, reflecting the capabilities of the system to

keep information about it, interact with it, or both.

Objects are entities in a software system which

represent instances of real-world and system

entities

Concept, abstraction or thing with identity

It knows things (has attributes)

It does things (provides services or has methods)

3

OBJECTS

4

Object Identity Behaviors State

An employee “Mr. John” Join(),

Retire()

Joined,

Retired.

A book “Book with title

Object Oriented

Analysis Design”

AddExemplar, Rent,

available,

reserved

A sale “Sale no 0015,

15/12/98”

SendInvoiced(),

Cancel().

Invoiced,

cancelled.

CLASS

Class is a description of a set of objects that share

the same attributes, operations, methods,

relationship and semantics.

Object classes are templates for objects. They may

be used to create objects.

An object represents a particular instance of a

class.

EX - class car, defines the property color.

Each individual car object i.e. alto or zen or i10

will have a value for this property, such as

"maroon," “silver" or "white."

5

TERM OF OBJECTS

Attribute: data items that define object.

Operation: function in a class that combine to form

behavior of class.

Methods: the actual implementation of procedure

(the body of code that is executed in response to a

request from other objects in the system).

6

CLASS DIAGRAM

CLASS DIAGRAM

Graphic notation for modeling classes & relationship.

Use to represent structure of applications.

OBJECT DIAGRAM

Shows individual objects, relationship & helpful for

documenting test cases & discussing for example.

7

Person

class objects

Smith : Person

Atul : Person

Class Diagram-VALUES & ATTRIBUTES

Value is piece of data

Attribute is a named property of class that describe a

value held by each object of class.

“Object is to a class as as value is to attributes”

8

Person

name

birthdate

Joe:Person

name=”Joe”

birthdate=21 oct 1983

Class with

attribute Object with

values

Modeling Notation

Person

name : string

birthdate : date

Joe:Person

name = ”Joe”

birthdate = 21 oct 1983

9

•attribute second compartment of class

•Type & default Value are optional

• colon precedes type.

•Attribute name is left align & uses a lowercase letter

Class with attribute

Object with values

•Value second compartment of object

•Use equal sign for value.

OPERATIONS & METHODS OPERATIONS :-Function applied to or by object

Company Hire, Fire & pay bonus

Window Open,close,hide,redisplay

“Same Operation applied to many different classes”. Concept called??????

METHODS :- Implementation of operation for a class

Ex:- Class File Print operation

Implement Different methods to print

ASSCII file, Binary file & picture file

Person

name

birthdate

changejob

changeaddress

File

filename

sizeinbyte

lastupdate

print 10

List operation3rd

Compartment

Opn name regular face

Left align

Lowercase letter

SUMMARY OF NOTATIONS FOR CLASSES

ClassName

attributename1 : dataype1 = defaultvalue1

attributename2 : dataype2 = defaultvalue2

…………………………

operationName1 (argumentlist1) : resultType1

operationName2 (argumentlist2) : resultType2

…………………………

Notation for argument of operation

Direction argumentName : type = defaultvalue

11 name(parameter list) : type of value returned

12

Class

Name

Operation

Attributes

13

Links & Association Concepts

Link Connection among object

Instance of an instance.

EX - Joe works for abc company

tuple, that is a list of objects.

instance of an association.

Association Group of links with common structure

& semantics

Set of links in a class

EX – a person works for company

UML Notation:-link line between objects

If link have name it is underlined

Association line between classes

Arrange association from left to right

14

Examples of Association

A Cup of Tea is drunk by one Person.

A Person drinks zero or more Cups of Tea.

Worksfor connects person to company

Employs connects company to person

REFERENCE :-It‟s a attribute in one object that refers to another object

Ex:-Person object employer that refers to company

Company Object employees that refers to Person

15

MULTIPLICITY

how many instances of one class relate to instances of

other class

how many objects participate in a relationships

16

Country

name

CapitalCity

name

HasCapital

Obj.

Dia.

1 1

France:Country

name =“France”

Paris:CapitalCity

name = “Paris”

HasCapital

India:Country

name =“India”

NewDelhi:CapitalCity

name =“NewDelhi”

HasCapital

Canada:Country

name=“Canada”

Ottawa:CapitalCity

name=“Ottawa”

HasCapital

Class Dia.

Association

or link?

17

Person

name

Company

name

OwnsStock

* * Class Dia.

Many-to-Many Association

Bank

name

Person

name

Account

* 0….1

Obj

Dia.

Zero-to-one Association

A B Association

Association Vs Link

* * AnotherAssociation * *

anA:A aB:B aLink

anotherLink

Class Dia.

Class Dia.

Symbol Meaning

1 One and only one

0..1 Zero or one

M…N From M to N (natural integer)

0..* From zero to any positive integer

1..* From one to any positive integer

Specified range

CARDINALITY :- Number of instances of each class

involved

•Multiplicity constraint on size of a collection

•Cardinality Count of element that are actually in a

collection

2..4

18

ASSOCIATION END NAMES

Multiplicity referred to end of association.

Can give name to it.

Ex:-one to many multiplicity one & end with

multiplicity of many.

Employee employer

joe TCS

mary Infosys

Useful for traversing association without explicitly

mentioning association

19

Person

name

Company

name WorksFor * 0..1

employee employer

Association end name are necessary for association

between two objects of same class

Distinguish multiple association between a pair of

classes

All association end name attached to a class must

be unique

A directory may contain many lesser directories &

may optionally be contained itself.

20

User Directory

owner

authorizedUser * *

* 1

*

0..1 container

contents

ORDERING

Objects on “many” association end have no explicit

order & used as set.

Ex:-A screen containing no. of overlapping windows

Each window on a Screen occurs at most one

Only top most window is visible at any point on screen

21

Screen Window {ordered}

VisibleOn 1 *

BAGS & SEQUENCE

binary association one link for a pair of objects

permit multiple links for a pair of objects by

annotating an association end with {bag} or

{sequence}

Bag collection of elements with duplicates allowed.

Sequence ordered collection of elements with

duplicates allowed

22

ASSOCISATION CLASS

Ability to describe links of association with attributes

like any class.

An association class is an association that is also a

class that have attributes & operations.

23

Figure represents attributes for two one-to-many

& one-to-one association

24

Fig. shows how it is possible to fold att. For one-to-one

& one-to-many association into class.

This is not possible for many-to-many associations

Multiplicity of association might changes.

25

Authorization

priority

privileges

startsession

26

User Workstation

Directory homedirectory

*

* *

1

Fig. shows association class participating in association

User (authorized ) many workstations

User has home directory for each workstation

but several workstation &

user can share same home directory

QUALIFIED ASSOCIATION

association in which an attribute called Qualifier

disambiguates the objects for a „many‟ association‟ end.

A qualifier selects among the target objects, reducing

the effective multiplicity from „many‟ to „one‟.

Both below models are acceptable but the qualified

model adds information.

27

A stock exchange list many companies.

It list only one company with given ticker symbol.

A company may be listed on many stock exchange.

28

Generalization/Inheritance

relationship between superclass & subclasses

Organizing the classes By

similarities

differences,

structuring the descriptions of objects.

A superclass holds common attributes, operations and

associations.

A subclass may:

inherits its parent‟s attributes, operations, and

relationships

Add additional attributes, operations,relationships

They inherit the features of their superclass.

Generalization is called a “IS A” relationship

29

30

Example:

Single

Inheritance

a subclass inherits from one or more superclasses

Single inheritance

Multiple inheritance

Account

balance name number

Withdraw() CreateStatement()

Checking

Withdraw()

Savings

GetInterest() Withdraw()

Superclass

(parent)

Subclasses

Generalization

Relationship

Ancestor

Descendents

31

Use of generalization

Support of polymorphism:

polymorphism increases

the flexibility of

software.

Adding a new subclass and automatically

inheriting superclass behavior.

Structuring the description of objects:

Forming a taxonomy (classification), organizing

objects according to their similarities. It is much

more profound than modeling each class

individually and in isolation of other similar

classes.

Enabling code reuse:

Reuse is more productive than repeatedly writing

code from scratch. 32

Generalization : - superclass generalize the

subclasses

Specialization :- subclasses refine or specialize

the superclass

Inheritance :- it‟s a mechanism for sharing of

attributes, operations & association

33

OVERRIDING FEATURE

A subclass may override a superclass feature

(attribute default values, operation) by redefining a

feature with the same name.

Never override the signature of methods.

34