3. What is Object?
• Tangible entity and close to real world
• It has state and behavior
• It has responsibilities, it has to adhere to
• It expects respect from rest of the world
• It provides services to other objects
• World is collection of collaborating entities
called “objects”
• Object is born and it has to die
5. Abstraction
• An abstraction denotes the essential
characteristics of an object that distinguish it
from all other kinds of objects and thus
provide crisply defined conceptual
boundaries, relative to the perspective of
the viewer
• Focuses upon the observable behavior of the
object
6. Abstraction
• Abstraction provides reusability
• More generic than specific
– “Take me to airport” Vs “Turn Left”, “Turn Right”,
“Start”, “Stop”
• Abstraction provides a mean to divide and
conquer problem statement
• Abstraction helps in pattern identification
• Abstract classes and Interfaces
8. Encapsulation
• An object should only expose the services required to interact
with it. Details not important to the user of the object should
be hidden
• Services are implemented by the object
• # of services should be kept minimal
• Any local changes (algorithm/data) will not affect the service
provided. This makes system resilient.
• Services provided by the object should be seen as a contract
between user-of-the-object and object-under-discussion. Both
the parties should honor the contract.
• The scope of data manipulation code is limited to the object
thus provides better control on the data.
• Give the user objects only what they absolutely needs
• Services are exposed as “public” access-modifier
9. Inheritance
• “Is-a” relationship
• Helps in code/services reuse
• Helps in locating the common code at one
place hence a common change can be
applied at one place only. Hence less
maintenance efforts & increased readability
• Base class services can be used as-it-is or
can be overridden
10. Polymorphism
• Literal meaning: many Shape
{
shapes }
public void Draw();
• Provides analogous Circle Rectangle
interface (with different {
public void Draw()
{
public void Draw()
implementation) to {
}
{
}
users of object
} }
• Polymorphism-
Abstraction-inheritance
often go hand in hand
11. Using “private, public, protected”
wisely
Private
• Internal to object
– Class level variables
– Sub routines
• Does not make much sense out side the object boundaries
– Helper methods
• Needs to be secured/shielded from out side world
– Variables holding important information crucial for algorithms and
values needs to be checked before assigning/setting
• Contributes to the stable-state of the object
– Object attributes
12. ………Using “private, protected, public”
wisely
Protected
• Internal to object and its derived objects and Does not make
much sense out side the object boundaries but may be
assessed by derived objects
– Helper methods
Public
• Only meant for out side world
• Mostly represent the services provided by object
• Can be overridden by derived objects