You are on page 1of 26

CS F213

Object Oriented Programming


Prof.R.Gururaj
BITS Pilani CS&IS Dept.
Hyderabad Campus
Classes
and
Objects

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Ch.2 of R1.
The Complete Reference- Java, 7th Edition, Herbert
Schildt, Tata McGraw Hill Publishing.

Ch.3 of R2. Object Oriented Analysis and Design with


Applications, Grady Booch, Addison Wesley, 2nd Edition.

And also refer to Class notes.

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Objects
The ability to recognize the physical objects is a skill
humans possess.
We understand that an object is a tangible entity that
exhibits some well-defined behavior.
An object can be any of the following:
1. A tangible and/or visible thing.
2. Something towards which our thought or action is
directed.
3. Something that may be understood intellectually.

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Real-world objects are not the only kind of objects that are
of interest to us in SW development.
Other important kinds of objects are inventions of the
Design process whose collaboration with other such
objects to provide some high-level behavior or
functionality.

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


An object represents an individual, identifiable item,
unit, or entity either in the real world or abstract,
with a well-defined role in the problem domain.

An object is anything that has crisply defined boundary.

Speed, color, temp etc. can not become objects. These


are actually properties of other objects.

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


An object has state, behavior, and identity; the
structure and behavior of similar objects are defined
in their common class; the terms instance and object
are interchangeable.

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


State of an object
The state of an object encompasses all the properties
(usually static) of an object plus the current (usually
dynamic) values of each of these properties.

All properties have values- simple or another object.

Every object has a state implies that every object takes


up some amount of space, be it in the real world, or
in the computer memory.

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Behavior of an object
Objects dont stay in isolation.
They keep interacting with each other.
They act upon others and similarly are acted upon by
other objects.

Behavior is how an object acts and reacts, in terms of


its state changes and message passing.

Behavior of an object represents its outwardly


visible activity.
Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus
We use the terms operation and message
interchangeably.

Some operations may change the state of an object and


some may not.
The operations that clients may perform upon an
object are generally declared as methods.

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


An operation denotes a service that a class offers to its
clients.
Modifier - an operation that alters the state.
Selector - to access the state of an object.
Iterator - to access parts of an object in a well defined
way.
Constructor-
Destructor -

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Roles and Responsibilities
The methods of an object comprise its protocol.
It is useful to divide this large protocol into logical
groupings.
Each partition denotes a role it can play.
Each role has some responsibilities.

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Objects as machines
Object has state.
Hence it can behave like a machine.
In many cases we can characterize the behavior of an
object using finite state machine.
Active Object owns execution control, autonomous
Passive object-

Multiple Active classes means multiple Threads of control.

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Identity of an object
Identity is that property of an object which
distinguishes it from all other objects.

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Parameter passing.
Call by Value and call by reference.
Object lifetime: It lives from the time it is created (using
new operator) until its space is reclaimed.
Memory leak:
Persistent objects:
transcend the lifetime of the program that created it.

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Relationships among Objects
Objects contribute to the behavior of the system by
collaborating with one another.
Link: Physical or conceptual connection between two
objects.
A link denotes the specific association between objects.
Through this an object applies for a service of another
object.
As a participant in a link, an object may play following
roles-
Actor; Server; Agent

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Links among Objects

u: User d: DB

a: ATM

Message Passing: u passing a message to a. and a passing a


message to d.
Visibility: the object u to pass a message to a, the object a
must be visible to u.

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Aggregation
Links denote peer-to-peer or client/server relationships.
Aggregation denotes a whole-part hierarchy. In the sense it
is a specialized kind of association.
This could be physical or conceptual.
Ex: Desks are part of ClassRoom. (physical)
A graduate program has courses (conceptual).

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Aggregation
Aggregation encapsulates parts as secrets of whole.
Links enable looser coupling among objects.
An object that is part of another has a link to aggregate.
Aggregate can send a message to part through this link.

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Class
A class represents a set of objects that share a common
structure and a common behavior.
A single object is an instance of a class.
An individual object is a concrete entity that performs
some role in the overall system.
The class captures the structure and behavior common
to all related objects.

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Class
The interface of a class provides its outside view and
therefore helps in hiding the structure and secrets of
behavior.
By contrast the implementation of a class is its inside view,
which encompasses the secrets of its behavior.
Types of interfaces:
Public ; Private; Protected

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Relationships among Class
Classes may be related in many interesting ways:

Association structural links; Ex. Aggregation.


Inheritance (generalization)
Dependency- ( change in one class may affect other class )

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Measuring the quality of
abstraction

Coupling (measure of strength of association)


Cohesion (degree of connectivity among the elements
of an abstraction)

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Criteria to be considered for
making decisions on operations

Reusability
Complexity
Applicability (is the behavior relevant to the type or
not).
Implementation knowledge (does implementation
depend on the internal details of type?)

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Visibility

Supplier is global to client


Supplier object is passed on to the client as a
parameter through some method
Supplier is part of client
Local to client method.

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus


Summary
Object - state, identity, and behavior
Active/passive objects
Parameter passing
Types of operations
Link and Aggregation
Class
Relationships
Quality of abstraction
Criteria for operations

Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus

You might also like