/
OBJECT BASICS (CH-2) OBJECT BASICS (CH-2)

OBJECT BASICS (CH-2) - PowerPoint Presentation

conchita-marotz
conchita-marotz . @conchita-marotz
Follow
401 views
Uploaded On 2017-05-05

OBJECT BASICS (CH-2) - PPT Presentation

SCE KIIT University 1 KIIT CSEIT OOSD Topics to be Discussed INTRODUCTION AN OBJECT ORIENTED PHILOSOPHY OBJECTS CLASSES OBJECT RESPONDS TO MESSAGES OBJECT RELATIONSHIP AND ASSOCIATIONS ID: 544668

kiit object oosd cse object kiit cse oosd objects class message relationship contd

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "OBJECT BASICS (CH-2)" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

OBJECT BASICS (CH-2)

SCE, KIIT University

1

KIIT CSE/IT (OOSD)Slide2

Topics to be Discussed

INTRODUCTION

AN OBJECT ORIENTED PHILOSOPHYOBJECTS

CLASSES

OBJECT RESPONDS TO MESSAGES

OBJECT RELATIONSHIP AND ASSOCIATIONSCONSUMER-PRODUCER ASSOCIATIONAGGREGATION AND OBJECT CONTAINMENT

2

KIIT CSE/IT (OOSD)Slide3

INTRODUCTION

What is an object ?

Ans: A car is an object; a real world entity , identifiably separate from its surroundings.Car has well defined

attributes

:

ColorManufacturerCost Owner3

KIIT CSE/IT (OOSD)Slide4

1. INTRODUCTION

contd….

Car has well defined set of things we do with it(i.e methods

) :

Drive it

Lock itTow itCarry passengerWhat do object have to do with system development ?4

KIIT CSE/IT (OOSD)Slide5

1. INTRODUCTION

contd….

Properties or attributes describe the state (data) of an object.

Methods (procedures)

defines its behavior.

5KIIT CSE/IT (OOSD)Slide6

2. AN OBJECT ORIENTED PHILOSOPHY

The difference comes among them are :

The ease of description

Reusability

Extensibility

ReadabilityComputational efficiencyAbility to maintain the description6

KIIT CSE/IT (OOSD)Slide7

2. AN OBJECT ORIENTED PHILOSOPHY

contd….

It has been said that one should speak:English for businessGerman for engineering

Persian for poetry

A similar quip can be made for programming languages.

Traditional languages were more machine dependant 7KIIT CSE/IT (OOSD)Slide8

2. AN OBJECT ORIENTED PHILOSOPHY

contd….

Fundamental characteristic of OOP is that it allows the base concepts of the language to be extended to include ideas and terms closer to those of its application.

New data types can be defined in terms of existing data types.

FUNDAMENTAL DIFFERENCE BETWEEN THE OBJECT ORIENTED SYSTEMS AND TRADITIONAL SYSTEMS ARE:

KIIT CSE/IT (OOSD)8Slide9

2. AN OBJECT ORIENTED PHILOSOPHY

contd….

Traditional Systems:Most traditional development methodologies are either

algorithm centric

or

data centric.In an algorithm centric methodology you can think of an algorithm that can accomplish the task, then build data structures for that algorithm to use.In a data centric methodology, you think how to structure the data, then build the algorithm around that structure.

KIIT CSE/IT (OOSD)

9Slide10

2. AN OBJECT ORIENTED PHILOSOPHY

contd….

In traditional approach a lot of code was written to do all the things that have to be done.

The code is the plan, brick, and mortar for building a structure(

Code Centric

).Code is the active entity here.KIIT CSE/IT (OOSD)10Slide11

2. AN OBJECT ORIENTED PHILOSOPHY

contd….

Object-Oriented Systems:Here the

algorithm and the data structures

are

packaged together as an object, which has a set of attributes or properties.The state of these attributes is reflected in the values stored in its data structures.Objects has a collection of methods or proceduresAttributes and methods are equal and inseparable parts of the object

KIIT CSE/IT (OOSD)

11Slide12

2. AN OBJECT ORIENTED PHILOSOPHY

contd….

OOP languages bridge the semantic gap between the ideas of the application and those of the underlying machine &Objects represent the application data in a way that is not forced by hardware architecture.

KIIT CSE/IT (OOSD)

12Slide13

3. OBJECTS

The term object was first utilized in the

Simula language.The term object

means a combination of data and logic that represent some real world entity.

KIIT CSE/IT (OOSD)

13Slide14

3. OBJECTS

contd….

The

“data”

part of this object would be:

Car’s name , color, number of doors, price etcThe “logic” part of the object could be collection of program:Show mileage, change mileage, stop, goKIIT CSE/IT (OOSD)

14Slide15

What is an Object?

Informally, an object represents an entity, either physical, conceptual, or software

A more formal definition:An object is a concept, abstraction, or thing with sharp boundaries and meaning for an application An object is something that has:

State

Behavior

IdentityKIIT CSE/IT (OOSD)15Slide16

3. OBJECTS

contd….

When developing an object-oriented application, two basic questions always arise:What objects does the application need ?

What functionality should those object have ?

Programming in an object-oriented system consists of adding new kinds of objects to the system an defining how they behave.

Eg: of objects: Windows, Spreadsheet, etc.KIIT CSE/IT (OOSD)

16Slide17

4. CLASSES

Classes

are used to distinguish one type of object from another.

Eg

: class eagle or class airplane, class car.

As per O-O systems, a class is a set of objects that share a common structure and a common behavior; a single object is simply an instance of a class.A class is a specification of - structure (instance variables), - behavior (methods),

- inheritance for objects.

KIIT CSE/IT (OOSD)

17Slide18

What is a class?

A class represents a

template for several objects and describes how these objects are structured internallyObjects of the same class have the same Objects of the same Class have the same definition both for their operations and their information structure

Class is an Class is an

implementation of objects

An object is an instance of a classA class is an abstraction in that it:Emphasizes relevant characteristicsSuppresses other characteristicsKIIT CSE/IT (OOSD)

18Slide19

Class

A class is comprised of three sectionsThe first section contains the class name

The second section shows the structure (attributes)The third section shows the behavior (operations)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

Objects are grouped into classesKIIT CSE/IT (OOSD)

19Slide20

5. OBJECT RESPONDS TO MESSAGES

Object capabilities are determined by the

methods

defined for it.

Methods are conceptually equal to the function definitions used in procedural language.

Objects perform operations in response to messages.Eg: When you press on the break pedal of a car, you send a stop message to the car object.KIIT CSE/IT (OOSD)

20Slide21

5. OBJECT RESPONDS TO MESSAGES

contd….

Messages essentially are nonspecific function calls.A message is different from a subroutine call; how ?

Since different objects can respond to the same message in different way.

KIIT CSE/IT (OOSD)21Slide22

Eg

: Cars, motorcycles & bicycles will all respond to a stop message but differently.

KIIT CSE/IT (OOSD)

22

Stop MessageSlide23

5. OBJECT RESPONDS TO MESSAGES

contd….

NOTE: Messages makes no assumptions about the class of the receiver or the arguments; they are simply objects.

It is the receiver’s responsibilities to respond to the message appropriately.

This gives

flexibility, as different objects can respond to the same message in different ways.This is known as polymorphism. It is the main difference between a message and a subroutine call.KIIT CSE/IT (OOSD)

23Slide24

Difference Between Message & Method

KIIT CSE/IT (OOSD)

24

1.

Cook Rice

2.

Wash All the vegetables.

3.

Marinate the same with Yogurt & ginger-garlic paste

for about an hour.

4

Heat a fry-pan with Oil , add Onions etc

5.

Cover & let it sit for a few minutes before serving.

MESSAGE

OBJECT

Instruction

METHOD

Way it is Prepared

Vegetable

BiriyaniSlide25

5. OBJECT RESPONDS TO MESSAGES

contd….

In other words, message is the instruction

and the

method

is the implementation.Objects respond to messages according to methods in its class.KIIT CSE/IT (OOSD)

25

Car Object

………………………………….……

Brake

5 Object

………………………………….……

* 7Slide26

5. OBJECT RESPONDS TO MESSAGES

contd….

A message has a name, just like a method, such as cost, set cost, cooking time.An

object understands a message

when it can match the message to a method that has a

same name as the message. A message differs from a function in that a

function says “how to do something” and a

message

says “

what to do

”.

KIIT CSE/IT (OOSD)

26Slide27

Encapsulation and Information Hiding

A concept of

‘Self-containing’ Information hiding – is the principle of concealing the data and procedures of an object

‘internal ’

structure is hidden from their surroundings

Functionality and behaviour characterised by ‘interfacing’ operationsData Abstraction is a benefit of OO

concept that incorporates encapsulation and polymorphism.

KIIT CSE/IT (OOSD)

27Slide28

Some more O-O Concepts

Class Hierarchy

Single InheritanceMultiple Inheritance

Multilevel Inheritance

Dynamic Inheritance

: Allows objects to change and evolve over time. It refers to the ability to add, delete, or change parents from objects(or Classes) at run time. Eg: Window object changing to an icon and a Vice versa.PolymorphismKIIT CSE/IT (OOSD)

28Slide29

Polymorphism

A concept in type theoryA common name may denote instances

of different classesOne type of operation can be implemented in different ways by different classesOverloading in modern OO language

KIIT CSE/IT (OOSD)

29Slide30

Why Polymorphism?

A very strong tool for allowing system designers to develop

flexible systemsDesigner only need to specify what shall occur and not occur and not

how it shall occur

To add an object, the modification will only affect the new object, not those using it

KIIT CSE/IT (OOSD)30Slide31

Inheritance

“If class B inherits class A, then both operations and the information structure described in class A will become part of class B”

KIIT CSE/IT (OOSD)

31Slide32

Inheritance

KIIT CSE/IT (OOSD)

32Slide33

Why Inheritance?

Show similarities

Reuse common descriptionsSoftware Reuse

Easy

modification of model by performing

modification in one place Avoid redundancy , leading to smaller and more efficient model, easier to understandKIIT CSE/IT (OOSD)

33Slide34

6. OBJECT RELATIONSHIP AND ASSOCIATIONS

ASSOCIATIONS

represents the relationships between objects and classes.

Cardinality

specifies how many instances may relate to a single instance of an associated class. Eg: one or many, one to many etcMultiplicity value (i.e the number of objects that participate in the association)

KIIT CSE/IT (OOSD)

34

PILOT

AIRPLANES

Can fly

Flown bySlide35

What is Cardinality?

Definition:

Number of instances of each class involved in the dialogue is specified by cardinality.Common multiplicity values: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 integer1..* From one to any positive integerAlso thought can be given about navigability to every applicable relationship.KIIT CSE/IT (OOSD)

35Slide36

6. OBJECT RELATIONSHIP AND ASSOCIATIONS

contd….

KIIT CSE/IT (OOSD)

36

Notations associated in an association:

Eg: Slide37

7. CONSUMER-PRODUCER ASSOCIATION

KIIT CSE/IT (OOSD)

37

It is a special form of association also known as

client-server

association or use relationship.It is viewed as one-way interaction.

PrintServer

Item

Request for printing

CONSUMER object requests service

PRODUCER provides service Slide38

Association and Link

A link:

An instance of an association

Exists between two or more objects

Dynamically created and destroyed as the run of a system proceeds

For example:

An employee joins an organization.

Leaves that organization and joins a new organization etc.Slide39

Relationships

AssociationAggregation

CompositionDependencyGeneralizationRealization

KIIT CSE/IT (OOSD)

39Slide40

ASSOCIATION

These are the most general type of relationship:

It denotes a semantic connection between two classes It shows BI directional connection between two classes

It is a weak coupling as associated classes remain somewhat independent of each other

Example:

KIIT CSE/IT (OOSD)

40Slide41

Association Relationship

Library Member

Book

1

*

borrowed bySlide42

3-ary Association

Skill

Person

Competency

level

*

*Slide43

Aggregation Relationship

Represents whole-part relationship

Represented by a

diamond

symbol at the composite end.

Cannot be reflexive(i.e. recursive)

Not symmetric

It can be transitiveSlide44

Aggregation Relationship

Document

Line

1

*

Paragraph

1

*Slide45

Composition Relationship

Order

1

*

Item

Life of item is same as the orderSlide46

Relationships: Composition

KIIT CSE/IT (OOSD)

46

A form of aggregation with strong ownership and coincident lifetimes

The parts cannot survive the whole/aggregate

This is a strong form of aggregation It expresses the stronger coupling between the classesSlide47

An aggregate object contains other objects.

Aggregation limited to

tree hierarchy

:

No circular inclusion relation.

Aggregation

cont…

Slide48

Aggregation vs. Composition

Composition:

Composite and components have the same life.

Aggregation:

Lifelines are different.

Consider an

order

object:

Aggregation:

If order items can be changed or deleted after placing the order.

Composition:

Otherwise.Slide49

Composition versus Aggregation

Order

Item

1

*

Order

Item

1

*

Composition

AggregationSlide50

8. AGGREGATION AND OBJECT CONTAINMENT

Some objects may be composed of and may contain other objects.

Since each object has an identity, one object can refer to other objects.This is known as

AGGREGATION

, where an attribute can be an object itself.

Eg: A car object is an aggregation of engine, seat, wheels, and other objects.KIIT CSE/IT (OOSD)

50Slide51

8. AGGREGATION AND OBJECT CONTAINMENT

contd….

KIIT CSE/IT (OOSD)

51

Fig:A

car object showingaggregation.

Car

Engine

Seat

WheelSlide52

Relationships: Dependency

A relationship between two model elements where a change in one may

cause a change in the otherNon-structural, “using” relationship

KIIT CSE/IT (OOSD)

52Slide53

Relationships: Generalization

A relationship among classes where one class shares the structure and/or behavior of one or more classes

Defines a hierarchy of abstractions in which a subclass inherits from one or more superclassesSingle inheritance

Multiple inheritance

Generalization is an “is-a-kind of” relationship

KIIT CSE/IT (OOSD)53Slide54

Relationships: Realization

One classifier serves as the contract that the other classifier agrees to carry outFound between:

Interfaces and the classifiers that realize them

KIIT CSE/IT (OOSD)

54Slide55

The Relationship Between Classes and Objects

A class is an abstract definition of an object

It defines the structure and behavior of each object in the classIt serves as a template for creating objects Objects are grouped into classes

KIIT CSE/IT (OOSD)

55Slide56

Strengths of Object Orientation

A single paradigmFacilitates architectural and code reuse

Models more closely reflect the real worldMore accurately describe corporate data and processesDecomposed based on natural partitioning

Easier to understand and maintain

Stability

A small change in requirements does not mean massive changes in the system under developmentKIIT CSE/IT (OOSD)56Slide57

CASE STUDY

Do Self Study of A PAY ROLL PROGRAM of both Structured Approach and O-O Approach.

KIIT CSE/IT (OOSD)

57