55
jaya kolekar 1 06/17/22

OMD chapter 2 Class modelling

Embed Size (px)

Citation preview

Page 1: OMD  chapter 2 Class modelling

jaya kolekar

105/01/23

Page 2: OMD  chapter 2 Class modelling

Objects Define objects as a concept, abstraction or thing

with purposeful meaning.Two purpose of objects-Promote understanding of the real worldProvide a practical basis for computer

implementation.All objects have identity and are distinguishable.Object is a real-world entity that has state,

behavior & identity. Object rendered as rectangle with round corner.Example

2

STUDENT

Class

(STUDENT)Ram

(STUDENT)Jai

(STUDENT)

Objects05/01/23 jaya kolekar

Page 3: OMD  chapter 2 Class modelling

Classes An object class describes a group of objects with

similar properties (attributes), common behavior (operations), common relationships to other objects and common semantics.

Class rendered as rectangle with three compartments.

First compartment –class nameSecond compartment- attributesThird compartment - operationsExample

3

Class name

Attribute_name-1:data_type-1=default_value-1Attribute_name-2:data_type-2=default_value-2 --------------Operation_name-1(argument_list-1):result_type-1Operation_name-2(argument_list-2):result_type-2 …………………

Student

Roll-No : IntegerName : raj

Request_book()Return_book(book_id)

05/01/23 jaya kolekar

Page 4: OMD  chapter 2 Class modelling

Object diagram

405/01/23 jaya kolekar

Page 5: OMD  chapter 2 Class modelling

example

5

Person

Class Diagram

(Person)Ram

(Person)Jai

(Person)

Instance Diagram

05/01/23 jaya kolekar

Page 6: OMD  chapter 2 Class modelling

Attribute An attribute is a data value held by the objects in a

class.Each attribute name is unique within a class.An attribute should be a pure data value, not an object.Attributes are listed out in the second part of the class

box.Each attribute name may be followed by optional

details, such as type and default value.The type is preceded by a colon and default value is

preceded by an equal sign.Example

6

Person

name: stringage: integer

Class with Attributes

(Person)Ram

24

(Person)Jai34

Objects with Values

05/01/23 jaya kolekar

Page 7: OMD  chapter 2 Class modelling

Operations and MethodsAn operation is a function or transformation that may

be applied to or by objects in a class.

All objects in a class share the same operations.

The same operation may apply to many different classes, Such an operation is polymorphic

A method is the implementation of an operation for a class.

Operations are listed in the lower third of the class box.

Each operation name may be followed by optional details, such as argument list and result type.

705/01/23 jaya kolekar

Page 8: OMD  chapter 2 Class modelling

8

Personnameage

change-jobchange-add

Personnameage

change-jobchange-add

Personnameage

print

Filenamesize

Operations

Personnameage

change-jobchange-add

Personnameage

Move(delta:vector)Select(p:Point):Boolean

Rotate(angle)

Geometric objectColor

position

05/01/23 jaya kolekar

Page 9: OMD  chapter 2 Class modelling

Links and AssociationA link is a physical or conceptual connection between objects.

A link is an instance of an association.

An association describes a group of links with common structure and semantics.

All the links in an association connect objects from the same classes.

Association and links often appear as verbs in a problem statement.

9

(Person)raj

(Company)IBM

Works_for

Personname

Companyname

Works_for

05/01/23 jaya kolekar

Page 10: OMD  chapter 2 Class modelling

AssociationAssociations are bidirectional.In real, both directions of traversal are equally

meaningful and refer to same association.Associations are often implemented in

programming languages as pointers from one object to another.

All connections among classes should be modeled as association.

Association has three typesOne-to-one associationMany-to-many associationTernary association

1005/01/23 jaya kolekar

Page 11: OMD  chapter 2 Class modelling

11

Countryname

Cityname

Has-capital

(Country)India

(City)Delhi

Has-capital

Has-capital

Class Diagram

Instance Diagram

One-to-One Association and links

05/01/23 jaya kolekar

Page 12: OMD  chapter 2 Class modelling

12

Linename

Pointname

intersects2+

(Line)L1

(Line)L2

(Line)L3

(Point)P1

(Line)L4

(Line)L5

(Point)P2

Many-to-many Association and links

Class Diagram

Instance Diagram

05/01/23 jaya kolekar

Page 13: OMD  chapter 2 Class modelling

13

Project Language

Person

(Project)MIS

(Language).Net

(Project)CAD

(Language)C

(Person)Jai

Ternary Association and Links

05/01/23 jaya kolekar

Page 14: OMD  chapter 2 Class modelling

Multiplicity It specifies how many instances of one class

may relate to a single instance of an associated class.

In OMT solid ball -> zero or more objectIn OMT hollow ball -> optional (zero or one)

objectIn OMT line -> one objectMultiplicity depends upon assumptions and

how you define the boundaries of a problem.

1405/01/23 jaya kolekar

Page 15: OMD  chapter 2 Class modelling

Multiplicity ”1” exactly one “1…*” One or more “3-5” three to five “0..1” zero to one “2,4,18” two, four or eighteen Symbol * denotes “many”.

15

Class

Class

Class

Class Clas

sClas

s

Class

Class

Class

Class

Class

Class

05/01/23 jaya kolekar

Page 16: OMD  chapter 2 Class modelling

Link attributesAn link attribute is a property of the links in

an association.

16

File UserAccessible By

Access permission

/etc/temp read Ram/etc/temp read-write Mohan/usr/lgn read-write Shyam

Link Attributes for a many-to-many association05/01/23 jaya kolekar

Page 17: OMD  chapter 2 Class modelling

Modeling an Association as a ClassEach link becomes one instance of the class.

17

User WorkstationAuthorized on

AuthorizationPriority

PrivilegesStart session

Directory

Home directoryModeling an association as a class

05/01/23 jaya kolekar

Page 18: OMD  chapter 2 Class modelling

Role NamesA role is one end of an association.A binary association has 2 roles, each of

which may have a role name.A role name is a name that uniquely

identifies one end of an association.Roles often appear as nouns in problem

descriptions.Use of role name is optional.Role names are necessary for associations

between two objects of the same class.1805/01/23 jaya kolekar

Page 19: OMD  chapter 2 Class modelling

19

person companyemployee employer

Works-for

Employee Employer

Ram TCS

Mohan Wipro

Role names for an association

05/01/23 jaya kolekar

Page 20: OMD  chapter 2 Class modelling

Role Names

20

User Directory

owner

Authorized usercontents

container

05/01/23 jaya kolekar

Page 21: OMD  chapter 2 Class modelling

orderingIf order of objects requiredIndicated by writing “{ordered}” next to

multiplicity dot for the role.

21

window screen{ordered}

Visible-on

Ordered sets in an association

05/01/23 jaya kolekar

Page 22: OMD  chapter 2 Class modelling

QualificationIt relates two classes and a qualifier.Qualifier is a special attribute that reduces

the effective multiplicity of an association.One-to-many or many-to-many may be

qualified that can be reduced to one-to-one. ( but not always)

It distinguishes among the set of objects at the many end of an association.

A qualified association can also be considered a form of ternary association.

2205/01/23 jaya kolekar

Page 23: OMD  chapter 2 Class modelling

23

Directory FileFile name

A qualified association

A directory plus a file name yields a file

05/01/23 jaya kolekar

Page 24: OMD  chapter 2 Class modelling

AggregationIt is a part-of relationship It has transitivity property i.e. A is part of B

and B is part of C then A is part of C.It is anti symmetric i.e. if A is a part of B then

B is not a part of A.Aggregation is a special form of association.

24

document paragraph sentence

05/01/23 jaya kolekar

Page 25: OMD  chapter 2 Class modelling

AggregationIt is a form of association in which an

aggregate object is made of components.Components are part of aggregate.Aggregate is inherently transitive i.e. an

aggregate has parts which may in turn have parts.

2505/01/23 jaya kolekar

Page 26: OMD  chapter 2 Class modelling

Aggregation vs. AssociationAggregation is a special form of association. If two objects are tightly bound by a part-whole relationship,

it is an aggregation. If two objects are usually considered as independent even

though they may often be linked, it is an association.A company is an aggregation of its divisions which are in

turn aggregations of their departments; a company is indirectly an aggregation of departments.

A company is not an aggregation of its employees since the company and person are independent objects of equal structure and status.

26

company division department

person

Work for

05/01/23 jaya kolekar

Page 27: OMD  chapter 2 Class modelling

Recursive AggregatesTypes of Aggregation

Fixed aggregate : has a fixed structure , the number of types of

subparts are predefined. Eg : lamp

Variable aggregate: has a finite number of levels, but the number of parts

may vary. Eg : company and department

A recursive aggregation : contains directly or indirectly an instance of the same

kind of aggregate; the number of potential levels is unlimited .

Eg : computer program.

2705/01/23 jaya kolekar

Page 28: OMD  chapter 2 Class modelling

Simple Statement: x=i;

Block(combination of more than one simple statements):++i;x=i;

Compound Statement(single statement combines work of multiple statement optionally blocks): x=++i;

28

program

block

Compound statement

Simple statement

Recursive aggregate

05/01/23 jaya kolekar

Page 29: OMD  chapter 2 Class modelling

Generalization It is a relationship between a class & one or more refined

versions of it. the class being refined is called the super class & each refined

version is called a subclass.

It is “is-a” relationship because each instance of a sub class is an instance of super class as well.

The notation for generalization is a triangle with lines, super class connected by a line to the apex of the triangle and subclasses are connected by lines to a horizontal bar attached to the base of the triangle.

A discriminator is an attribute of enumeration type that indicates which property of an object is being abstracted by a particular generalization relationship

2905/01/23 jaya kolekar

Page 30: OMD  chapter 2 Class modelling

30

Inheritance for graphic figure

FigureColor

Center PositionThickness

MoveSelectDisplayrotate

0 D 1 D 2 D

Point Line Arc Spline circlePolygon

05/01/23 jaya kolekar

Page 31: OMD  chapter 2 Class modelling

Aggregation vs. GeneralizationAggregation relates instances. Two distinct objects are involved; one of

them is a part of the other.Generalization relates classes.Aggregation is often called “a part of”

relationship; generalization is often called “a kind-of” or “is-a” relationship.

Aggregation is sometimes called an “and relationship” and generalization refers to “or relationship”

3105/01/23 jaya kolekar

Page 32: OMD  chapter 2 Class modelling

32

lamp

base cover switch wiring

incandescentfluorescent

part4part3part2part1

Aggregation and generalization

05/01/23 jaya kolekar

Page 33: OMD  chapter 2 Class modelling

Propagation of operationsPropagation (triggering) is automatic

application of an operation to a network of objects when the operation is applied to some starting object.

E.g. moving an aggregation moves its parts; the move operation propagates to the parts.

Propagation can be possible for save, destroy, print and lock.

The operation does not propagate in reverse direction.

33

Person Document

copy

Paragraph

copy

Character

copyowns

copy copy

Propagation of operations05/01/23 jaya kolekar

Page 34: OMD  chapter 2 Class modelling

Abstract classesAn abstract class is a class that has no direct

instances but whose descendent classes have direct instances.

A concrete class is a class that is instantiable.

It may have abstract subclasses but they must have concrete descendents.

It may be leaf classes in the inheritance tree.

3405/01/23 jaya kolekar

Page 35: OMD  chapter 2 Class modelling

Abstract & concrete class

35

class

concrete abstractinstance

Leaf classNon leaf class

subclass1+ 1+

subclass

Has subclasses

Has subclasses

superclass

superclass

Directinstances

05/01/23 jaya kolekar

Page 36: OMD  chapter 2 Class modelling

Abstract classesIt’s organize features common to several classes.It’s frequently used to define methods to be inherited

by subclasses.It’s abstract operation defines the form of an

operation for which each concrete subclass must provide its own implementation.

Example of Abstract class & abstract operation

36

EmployeeEarning

Compute Pay {abstract}

SLRD EmployeeWeekly rate

Compute pay

exempt EmployeeMonthly rate

Compute pay

HRLY EmployeeHourly

Compute pay

05/01/23 jaya kolekar

Page 37: OMD  chapter 2 Class modelling

Overriding operations Overriding for Extension

The new operation is same as inherited except it adds some behavior usually affecting new attributes of the subclass.eg: window and labeledwindow has draw operation

Overriding for RestrictionThe new operation restricts the inherited.eg: set and integerset with operation add

Overriding for OptimizationThe new method must have the same external protocol (prototype) and results as the old one but its internal representation and algorithm may differ completely.Eg : integerset and sortintegerset with operation maximum

Overriding for ConvenienceThe new class is made a subclass of the existing class and overrides the methods that are inconvenient.

Eg:all query operations are inherited by all subclasses(read)3705/01/23 jaya kolekar

Page 38: OMD  chapter 2 Class modelling

Multiple inheritanceIt permits to have more than one super class and to inherit features

from all parents.

A class with more than one super class is called a join class.

A feature from the ancestor class found along more than one path is inherited only once.

Conflicts among parallel definitions create ambiguities that must be resolved in implementation.

A hollow triangle indicates disjoint subclasses while a solid triangle indicates overlapping subclasses.

The advantage of multiple inheritance is greater power in specifying classes and increased opportunity for reuse.

3805/01/23 jaya kolekar

Page 39: OMD  chapter 2 Class modelling

Multiple inheritance

39

vehicle

WatervehicleLandvehicle

boatamphibiousvehiclecar

Multiple inheritance from overlapping classes

[ join class ]

Overlapping Classes

05/01/23 jaya kolekar

Page 40: OMD  chapter 2 Class modelling

MetadataMetadata is data that describes other data.The definition of a class is metadata.Models are metadata since they describe the things being

modeled.RDBMS uses metadata.A class describes a set of instances of a given form.The dotted arrows connect the instances to the class.It is also useful for documenting examples and test cases.

40

Person

NameAge

weight

(Person)Name=ABC

Age=40Weight=40

(Person)Name=XYZ

Age=29Weight=70

Notation for instantiation05/01/23 jaya kolekar

Page 41: OMD  chapter 2 Class modelling

Class descriptorsClasses are meta objects and not real world

objects.

Class descriptors have features and they have their own classes which are called meta classes.

A class attribute describes a value common to an entire class of objects rather than data particular to each instance.

A class operation is an operation on the class itself.

4105/01/23 jaya kolekar

Page 42: OMD  chapter 2 Class modelling

Class descriptors

42

WindowSize:rectangle

Visibility:booleanDefault_size:rectangle

DisplayNew_window

Highest_priority_window

05/01/23 jaya kolekar

Page 43: OMD  chapter 2 Class modelling

Candidate keysA candidate key is a minimal set of attributes

that uniquely identifies an object or link.A class may have one or more candidate keys

each of which may have different combinations and numbers of attributes.

Each candidate key constrains the instances in a class.

Notation is {}

4305/01/23 jaya kolekar

Page 44: OMD  chapter 2 Class modelling

constraintsThese are functional relation between

entities of an object model.Entity includes objects, classes, attributes,

links and associations. A constraint restricts the values that entities

can assume.Simple constraints may be placed in object

models and complex may be in functional model.

4405/01/23 jaya kolekar

Page 45: OMD  chapter 2 Class modelling

45

Employee

salary

boss

{ salary < = boss.salary }

Window

Lengthwidth

{ 0.8 <= length / width < = 1.5 }

Constraints on objects

05/01/23 jaya kolekar

Page 46: OMD  chapter 2 Class modelling

General constraintsIt must be expressed with natural

languages or equations.Draw a dotted line between classes

involved in the constraint and specify the details with comments in braces.

46

Person Committee

Member_of

Chair_of{subset }

05/01/23 jaya kolekar

Page 47: OMD  chapter 2 Class modelling

Derived objects, links and attributes The notation for a derived entity is a slash or diagonal line on the corner of a class box, on an association line or in front of an attribute.

Show the constraint that determines the derived value. (optional)

47

Person Birthdate

/age

Current date

{ age = currentdate – birthdate }

05/01/23 jaya kolekar

Page 48: OMD  chapter 2 Class modelling

HomomorphismA mapping between mathematical structures of the same

type (eg groups or rings) that preserves the structure.similarity of form Homos = same & morphe = structure E.g. in a parts catalog for a automobile, a catalog item may

contain other catalog items.Each catalog item is specified by a model number that

corresponds to number of individual manufactured items, each with its own serial number.

The individual items are also composed of sub items.The structure of each item’s parts has the same form as the

catalog item’s parts.Thus the “contains” aggregation on catalog items is a

homomorphism of the “contains” aggregation on physical items.

4805/01/23 jaya kolekar

Page 49: OMD  chapter 2 Class modelling

Homomorphism It maps between two associations.

49

catalogItemModel#

ItemSl#

contains containsMaps

Describes

{ item 1 contains item 2 => item1.model contains item2.model }

Homomorphism for a parts catalog

05/01/23 jaya kolekar

Page 50: OMD  chapter 2 Class modelling

Homomorphism In general, a homomorphism involves 4

relationships among 4 classes.The homomorphism maps links of one

general association {u} into links of another general association {t} as a many-to-one mapping.

Two instantiation relationships map elements of one class into another: r is a many-to-one mapping from class B to A and s is a many-to-one mapping from class D to C.

5005/01/23 jaya kolekar

Page 51: OMD  chapter 2 Class modelling

Homomorphism

51

A

C

B

D

r

s

t u{u ( b, d)=>t ( b.r, d.s ) }

General Homomorphism

05/01/23 jaya kolekar

Page 52: OMD  chapter 2 Class modelling

Homomorphism In general where t is on a single class and u

is on a single class then A=C, B=D and r=s.Homomorphism is a special type of

relationship between relationships.

5205/01/23 jaya kolekar

Page 53: OMD  chapter 2 Class modelling

5305/01/23 jaya kolekar

Page 54: OMD  chapter 2 Class modelling

5405/01/23 jaya kolekar

Page 55: OMD  chapter 2 Class modelling

5505/01/23 jaya kolekar