Prof.R.Gururaj
CS&IS Dept.
Classes
and
Objects
Prof.R.Gururaj
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
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
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
Prof.R.Gururaj
Prof.R.Gururaj
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
Prof.R.Gururaj
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
Prof.R.Gururaj
Prof.R.Gururaj
Prof.R.Gururaj
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 objectMultiple Active classes means multiple Threads of control.
Prof.R.Gururaj
Identity of an object
Identity is that property of an object which
distinguishes it from all other objects.
Prof.R.Gururaj
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.
Memory corruption.
Persistent objects transcend the lifetime of the program
that created it.
Prof.R.Gururaj
d: DB
a: ATM
Synchronization Objects
When one object sends a message to another object across
a link, the two objects are said to be synchronized.
For objects in completely sequential applications, this
synchronization is achieved by simple method
invocation.
Prof.R.Gururaj
Synchronization Objects
When one active object has a link to a passive object, we
must choose one among the following for
synchronization.
approach
Description
Sequential
Guarded
Synchronous
Prof.R.Gururaj
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
Aggregation
Aggregation encapsulates parts as secrets of whole.
Links enable looser coupling among objects.
An object that is an aggregate of another has a link to
aggregate. Aggregate can send a message to part
through this link.
Prof.R.Gururaj
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.
Class captures the contractual (between abstraction
and client) decisions in the interface.
Prof.R.Gururaj
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
Quality of abstraction
Prof.R.Gururaj
Prof.R.Gururaj
Prof.R.Gururaj
Prof.R.Gururaj
Prof.R.Gururaj
Choosing Relationships
Collaborations (to invoke operations)
Aggregation
Inheritance
Prof.R.Gururaj
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
Summary