Top Banner
90
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: OOMD Unit 1,2
Page 2: OOMD Unit 1,2

Kiran Babu T.S

Assistant Professor

Dept of CSE

Kiran Babu T.S 2

Object-oriented modeling and design

Page 3: OOMD Unit 1,2

Introduction

Kiran Babu T.S 3

It is a new way of thinking about problems using models

based on real world concepts.

The basic construct is object which combines both data

structure and behavior in a single entity.

Rambaugh presents an object oriented software

development methodology, the Object Modeling

Technique (OMT) which extends from analysis through

design to implementation.

Page 4: OOMD Unit 1,2

Kiran Babu T.S 4

Analysis model is built to abstract essential aspects of application domain which contains objects found in application, their properties and behavior.

Then design model is made to describe and optimize the implementation.

Finally the design model is implemented in a programming language, database or hardware.

Graphical notation is used for expressing object-oriented models.

Page 5: OOMD Unit 1,2

What is object-oriented?

Kiran Babu T.S 5

Software is organized as a collection of discrete objects

that incorporate both data structure and behavior.

In general it includes- identity, classification,

polymorphism and inheritance.

Object Oriented Programming Language

= Object Based Programming Language(e.g. '83 Ada

and Modula-2)

+ Inheritance + Dynamic Binding

Page 6: OOMD Unit 1,2

Identity

Kiran Babu T.S 6

Identity means that data is organized into discrete,

distinguishable entities called objects.

Objects can be concrete or conceptual.

In real world an object simply exist but within a

programming language each object has a unique handle

by which it can be uniquely referenced.

The handle can be implemented by address, array index

or unique value of an attribute.

Page 7: OOMD Unit 1,2

Classification

Kiran Babu T.S 7

It means that objects with same data structure (attribute) and

behavior (operations) are grouped into a class.

A class is an abstraction that describes important properties

and ignores the rest.

Page 8: OOMD Unit 1,2

Polymorphism

Kiran Babu T.S 8

It means that the same operation (i.e. action or

transformation that the object performs) may behave

differently on different classes.

Specific implementation of an operation by a certain class is

called a method.

Page 9: OOMD Unit 1,2

Inheritance

Kiran Babu T.S 9

It is the sharing of attributes and operations among classes

based on a hierarchical relationship.

Subclasses can be formed from broadly defined class.

Each subclass incorporates or inherits all the properties of its

super class and adds its own unique properties.

Page 10: OOMD Unit 1,2

Object-oriented development?

Kiran Babu T.S 10

The theme is the identification and organization of

application concepts rather than final representation in a

prog. Language.

OOD approach encourages software developers to work

and think in terms of the application domain through

most of the software engineering life cycle.

It is a conceptual process independent of a programming

language until the final stage.

Page 11: OOMD Unit 1,2

Object-oriented methodology

Kiran Babu T.S 11

Stages-

Analysis

System design

Object design

implementation

Page 12: OOMD Unit 1,2

3 models

Kiran Babu T.S 12

Object model

Dynamic model

Functional model

Page 13: OOMD Unit 1,2

Object model

Kiran Babu T.S 13

Describes basic structure of objects and their relationship

Contains object diagram

Object diagram is a graph whose nodes are object classes

(Classes) and whose arcs are relationships among classes.

Page 14: OOMD Unit 1,2

Dynamic model

Kiran Babu T.S 14

Describes the aspects of a system that change over time.

It specifies and implement control aspects of a system.

Contains state diagram.

State diagram is a graph whose nodes are states and whose

arcs are data-flows.

Page 15: OOMD Unit 1,2

Functional Model

Kiran Babu T.S 15

Describes data value transformation within a system.

Contains data flow diagram.

Data Flow Diagram is a graph whose nodes are processes and

whose arcs are data flows.

Page 16: OOMD Unit 1,2

Object-Oriented concepts

Kiran Babu T.S 16

Abstraction

Encapsulation

Combining data and behavior

Sharing

Object structure, not Procedure Structure

Synergy

Page 17: OOMD Unit 1,2

Abstraction

Kiran Babu T.S 17

It consists of focusing on essential aspects of an entity and ignoring accidental properties.

The goal is to isolate those aspects that are important for some purpose and suppress those aspects that are unimportant.

Abstraction must always for some purpose because the purpose determines what is and what is not important.

Many different abstractions of same thing are possible, depending on the purpose for which they are made.

In building models, one must not search for absolute truth but for adequacy for some purpose.

A good model captures the crucial aspects of a problem and omits the others.

Focus on what an object is and does, not how to implement.

Page 18: OOMD Unit 1,2

Kiran Babu T.S 18

Page 19: OOMD Unit 1,2

Encapsulation

Kiran Babu T.S 19

Information hiding

Separating external aspects of an object which are accessible to other objects, from the internal implementation details of the object, which are hidden from other objects.

The implementation of an object can be changed without affecting the applications that use it.

Page 20: OOMD Unit 1,2

Kiran Babu T.S 20

Page 21: OOMD Unit 1,2

Synergy

Kiran Babu T.S 21

Identity, Classification, polymorphism and inheritance can be

used in isolation but together they complement each other

synergistically.

Page 22: OOMD Unit 1,2

Advantages of OOD……………

Kiran Babu T.S 22

Used in developing Compilers, Graphics, UI, databases, Object oriented languages, CAD systems, simulations, etc.

Used to document existing programs that are ill-structured and difficult to understand.

Not reduces development time; it may take more time than conventional development because it is intended to promote future reuse and reduce downstream errors and maintenance.

Page 23: OOMD Unit 1,2

Modeling

Kiran Babu T.S 23

A model is an abstraction of something for the purpose of

understanding it before building it.

The word model has 2 dimensions- a view of a system ( object,

dynamic or functional) and a stage of development ( analysis,

design or implementation)

Page 24: OOMD Unit 1,2

Kiran Babu T.S 24

Purpose –

Testing a physical entity before building it

Communication with customers

Visualization

Reduction of complexity

Page 25: OOMD Unit 1,2

Object Modeling

Kiran Babu T.S 25

Captures static structure of a system-

Objects in the system

Attributes

operations

Page 26: OOMD Unit 1,2

Objects

Kiran Babu T.S 26

Define objects as a concept, abstraction or thing with

purposeful meaning.

Two purpose of objects-

Promote understanding of the real world

Provide a practical basis for computer implementation.

All objects have identity and are distinguishable.

Page 27: OOMD Unit 1,2

Kiran Babu T.S 27

Page 28: OOMD Unit 1,2

Classes

Kiran Babu T.S 28

An object class describes a group of objects with similar

properties (attributes), common behavior (operations),

common relationships to other objects and common

semantics.

Page 29: OOMD Unit 1,2

Object diagram

Kiran Babu T.S 29

It provides a formal graphic notation for modeling objects,

classes and their relationships to one another.

Types-

Class diagram

Instance diagram

Page 30: OOMD Unit 1,2

Class diagram

Kiran Babu T.S 30

A class diagram is a schema, pattern or templates for

describing many possible instances of data.

Describes classes.

Page 31: OOMD Unit 1,2

Instance diagram

Kiran Babu T.S 31

Describes how a particular set of objects relate to each other.

Describes objects

Page 32: OOMD Unit 1,2

Kiran Babu T.S 32

Person

Class Diagram

(Person)

Ram

(Person)

Jai

(Person)

Instance Diagram

Page 33: OOMD Unit 1,2

Attribute

Kiran Babu T.S 33

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.

Page 34: OOMD Unit 1,2

Object Modeling Notations

Kiran Babu T.S 34

Person

name: string

age: integer

Class with Attributes

(Person)

Ram

24

(Person)

Jai

34

Objects with Values

Page 35: OOMD Unit 1,2

Operations and Methods

Kiran Babu T.S 35

An 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 i.e. the same operation takes on different forms in different classes.

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

Page 36: OOMD Unit 1,2

Kiran Babu T.S 36

Person

name

age

change-job

change-add

Person

name

age

change-job

change-add

Person

name

age

print

File

name

size

Operations

Page 37: OOMD Unit 1,2

Links and Association

Kiran Babu T.S 37

Links and associations are the means for establishing relationships among objects and classes.

A 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.

An association describes a set of potential links in the same way that a class describes a set of potential objects.

Page 38: OOMD Unit 1,2

Kiran Babu T.S 38

Associations 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.

A pointer is an attribute in one object that contains an

explicit reference to another object.

Page 39: OOMD Unit 1,2

Kiran Babu T.S 39

A link shows a relationship between two or more objects.

All connections among classes should be modeled as

association.

One-to-one association

Many-to-many association

Ternary association

Page 40: OOMD Unit 1,2

Kiran Babu T.S 40

Country

name

City

name

Has-capital

(Country)

India

(City)

Delhi

Has-capital

Has-capital

Class Diagram

Instance Diagram

One-to-One Association and links

Page 41: OOMD Unit 1,2

Kiran Babu T.S 41

Line

name

Point

name

intersects

2+

(Line)

L1

(Line)

L2

(Line)

L3

(Point)

P1

(Line)

L4

(Line)

L5

(Point)

P2

Many-to-many Association and links

Class Diagram

Instance Diagram

Page 42: OOMD Unit 1,2

Kiran Babu T.S 42

Project Language

Person

(Project)

MIS

(Language)

.Net

(Project)

CAD

(Language)

C

(Person)

Jai

Ternary Association and Links

Page 43: OOMD Unit 1,2

Multiplicity

Kiran Babu T.S 43

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

Hollow ball -> optional (zero or one)

Multiplicity depends upon assumptions and how you define the

boundaries of a problem.

Page 44: OOMD Unit 1,2

Link attributes

Kiran Babu T.S 44

An link attribute is a property of the links in an association.

Page 45: OOMD Unit 1,2

Kiran Babu T.S 45

File User Accessible By

Access permission

/etc/temp read Ram

/etc/temp read-write Mohan

/usr/lgn read-write Shyam

Link Attributes for a many-to-many association

Page 46: OOMD Unit 1,2

Kiran Babu T.S 46

Person

name

ssn

address

Company

Name

address

Works-for

Salary

Job-title

Performance rating

boss

manages

worker

Link attributes for one-to-many associations

Page 47: OOMD Unit 1,2

Modeling an Association as a Class

Kiran Babu T.S 47

Each link becomes one instance of the class.

Page 48: OOMD Unit 1,2

Kiran Babu T.S 48

User Workstation Authorized on

Authorization

Priority

Privileges

Start session

Directory

Home directory

Modeling an association as a class

Page 49: OOMD Unit 1,2

Role Names

Kiran Babu T.S 49

A 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.

Page 50: OOMD Unit 1,2

Kiran Babu T.S 50

person company employee employer

Works-for

Employee Employer

Ram TCS

Mohan Wipro

Role names for an association

Page 51: OOMD Unit 1,2

ordering

Kiran Babu T.S 51

If order of objects required

Indicated by writing “{ordered}” next to multiplicity dot for

the role.

window screen {ordered}

Visible-on

Ordered sets in an association

Page 52: OOMD Unit 1,2

Qualification

Kiran Babu T.S 52

It 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.

Page 53: OOMD Unit 1,2

Kiran Babu T.S 53

Directory File File name

A qualified association

A directory plus a file name yields a file

Page 54: OOMD Unit 1,2

Kiran Babu T.S 54

Company office Person organization

officer

Page 55: OOMD Unit 1,2

Aggregation

Kiran Babu T.S 55

It 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.

Page 56: OOMD Unit 1,2

Kiran Babu T.S 56

document paragraph sentence

Aggregation

Page 57: OOMD Unit 1,2

Aggregation

Kiran Babu T.S 57

It 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.

Page 58: OOMD Unit 1,2

Aggregation vs. Association

Kiran Babu T.S 58

Aggregation 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.

Page 59: OOMD Unit 1,2

Kiran Babu T.S 59

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.

Page 60: OOMD Unit 1,2

Kiran Babu T.S 60

company division department

person

Work for

Aggregation and Association

Page 61: OOMD Unit 1,2

Generalization

Kiran Babu T.S 61

It is a relationship between base class and sub class.

It is “is-a” relationship because each instance of a sub class is

an instance of super class as well.

Page 62: OOMD Unit 1,2

Kiran Babu T.S 62

Figure

Color

Pos

Thickness

Move

Select

Display

rotate

0 D 1 D 2 D

Point Line Arc Spline circle Polygon

Inheritance for graphic figure

Page 63: OOMD Unit 1,2

Aggregation vs. Generalization

Kiran Babu T.S 63

Aggregation 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”

Page 64: OOMD Unit 1,2

Kiran Babu T.S 64

lamp

base cover switch wiring

incandescent fluorescent

part4 part3 part2 part1

Aggregation and generalization

Page 65: OOMD Unit 1,2

Kiran Babu T.S 65

Aggregation can be fixed, variable or recursive.

A fixed aggregate has a fixed structure; the number and types

of sub parts are predefined e.g. lamp.

A variable aggregation has a finite number of levels but

number of parts may vary e.g. company.

Page 66: OOMD Unit 1,2

Kiran Babu T.S 66

A recursive aggregation contains directly or indirectly an

instance of the same kind of aggregate; the number of

potential levels is unlimited e.g. computer program.

Page 67: OOMD Unit 1,2

Kiran Babu T.S 67

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;

program

block

Compound

statement

Simple

statement

Recursive aggregate

Page 68: OOMD Unit 1,2

Propagation of operations

Kiran Babu T.S 68

Propagation (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.

Page 69: OOMD Unit 1,2

Kiran Babu T.S 69

A person owns multiple documents. Each document is composed of paragraphs that are in turn composed of characters. The copy operation propagates from documents to paragraphs to characters. Copying a paragraph copies all the characters in it.

The operation does not propagate in reverse direction.

Page 70: OOMD Unit 1,2

Kiran Babu T.S 70

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

Person

Document

copy

Paragraph

copy

Character

copy

owns

copy copy

Propagation of operations

Page 71: OOMD Unit 1,2

Abstract classes

Kiran Babu T.S 71

An 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 i.e. it can have direct instances.

A concrete class may have abstract subclasses but they must have concrete descendents.

Page 72: OOMD Unit 1,2

Kiran Babu T.S 72

only concrete classes may be leaf classes in the inheritance

tree.

Page 73: OOMD Unit 1,2

Abstract & concrete class

Kiran Babu T.S 73

class

concrete abstract instance

Leaf class Non leaf class

subclass

1+ 1+

subclass

Has subclasses

Has subclasses

superclass

superclass

Direct

instances

Page 74: OOMD Unit 1,2

Kiran Babu T.S 74

Abstract classes organize features common to several

classes

Abstract classes are frequently used to define methods to

be inherited by subclasses.

An abstract class can define methods to be inherited by

subclasses.

An abstract operation defines the form of an operation

for which each concrete subclass must provide its own

implementation.

Page 75: OOMD Unit 1,2

Kiran Babu T.S 75

Abstract class & abstract operation

Employee

Earning

Pay {abstract}

SLRD Employee

Earning

pay

HNRY Employee

Earning

pay

HRLY Employee

Earning

pay

Page 76: OOMD Unit 1,2

Overriding operations

Kiran Babu T.S 76

Reasons to use overriding-

For extension

For restriction

For optimization

For convenience

Page 77: OOMD Unit 1,2

Kiran Babu T.S 77

Extension

The new operation is same as inherited except it adds some behavior usually affecting new attributes of the subclass.

Restriction

The new operation restricts the inherited.

Optimization

The new method must have the same external protocol (prototype) and results as the old one but its internal representation and algorithm may differ completely.

Convenience

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

Page 78: OOMD Unit 1,2

Multiple inheritance

Kiran Babu T.S 78

It 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.

Page 79: OOMD Unit 1,2

Kiran Babu T.S 79

vehicle

Watervehicle Landvehicle

boat amphibiousvehicle car

Multiple inheritance from overlapping classes

[ join class ]

Overlapping Classes

Page 80: OOMD Unit 1,2

Kiran Babu T.S 80

A hollow triangle indicates disjoint subclasses while a solid

triangle indicates overlapping subclasses.

Page 81: OOMD Unit 1,2

Metadata

Kiran Babu T.S 81

Metadata 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.

Page 82: OOMD Unit 1,2

Kiran Babu T.S 82

A class describes a set of instances of a given form.

Instantiation relates a class to its instances.

The dotted arrows connect the instances to the class.

It is also useful for documenting examples and test cases.

Page 83: OOMD Unit 1,2

Kiran Babu T.S 83

Person

Name

Age

weight

(Person)

Name=ABC

Age=40

Weight=40

(Person)

Name=XYZ

Age=29

Weight=70

Notation for instantiation

Page 84: OOMD Unit 1,2

Class descriptors

Kiran Babu T.S 84

Classes 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.

Class attributes are useful for storing default information for creating new objects or summary information about instances of the class.

A class operation is an operation on the class itself.

The most common is to create new instances.

Operations on class structure are class operations.

Page 85: OOMD Unit 1,2

Class descriptors

Kiran Babu T.S 85

Window

Size:rectangle

Visibility:boolean

Default_size:rectangle

Display

New_window

Highest_priority_window

Page 86: OOMD Unit 1,2

Candidate keys

Kiran Babu T.S 86

A 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 {}

Page 87: OOMD Unit 1,2

constraints

Kiran Babu T.S 87

These 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.

Page 88: OOMD Unit 1,2

Kiran Babu T.S 88

Employee

salary

boss

{ salary < = boss.salary }

Window

Length

width

{ 0.8 <= length / width < = 1.5 }

Constraints on objects

Page 89: OOMD Unit 1,2

General constraints

Kiran Babu T.S 89

It 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.

Person Committee

Member_of

Chair_of

{subset }

Page 90: OOMD Unit 1,2

Derived objects, links and attributes

Kiran Babu T.S 90

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)

Person

Birthdate

/age

Current date

{ age = currentdate – birthdate }