Object:
Object is a real time entity which has real existence in the application.
Ø Is unique.
Ø Has an Identity.
Ø Contains attribute and behavior.
A software object is the representation of the real world object.
Class:
Class is a software template that defines the attribute and behavior to be included in the particular type of object.
Ø Is used to distinguish one type of object from another.
Ø Tells how an object looks like.
Ø Has virtual existence (made for categorize the objects based on their behavior and attribute).
Ø Does not do anything (Just tells what an object of particular type will do).
State behavior and identity:
State: The set of values that an object holds at a particular part of time. State of an object can change in time.
Behavior: Acts on the object and changes the state. Here the logic of the class is stored.
Behavior: Acts on the object and changes the state. Here the logic of the class is stored.
Identity: A name to the object which will separate it from all the other objects.
Example:
Abstraction:
Abstraction is the representation of a complex system into a general and relevant system
Ø Hides the complexity.
Ø Focus on The separation of an object’s essential behavior from its implementation.
Ø Data abstraction is also known as Data hiding
Ø Program to an interface, not to an implementation(good abstraction)
Example no. 1: One does not have to understand how the engine works to drive a car.
Encapsulation:
Encapsulation is a technique of wrapping up of the code and data to a single unit so that it can’t be access by the element outside of the wrapper.
Ø Provide security to data and function from being misused.
Ø Implemented using private, protected and public access modifier.
Ø Typically in a class :
State is private (not accessible externally)
Behavior is public (accessible externally)
Inheritance:
The ability of OOP to organize the classes in hierarchy where one class can acquire the properties of its super class called as inheritance.
Ø Represents a relationship between classes.
Ø Hierarchy can be considered as the rank or order of abstraction.
Ø Implemented in terms of subclass and super class.
Ø Sub classes have ability to acquire the visible responsibility defined in super class.
Ø The two most important hierarchies in a complex system are:
Class structure (‘is a’ hierarchy)
Object structure (‘has-a’ and Uses-A hierarchy)
Example:
Relationships among classes:
There are three types of relationships which can exist between classes:
Ø Is-A (or Kind-Of)
Ø Has-A (or Part-Of)
Ø Uses-A
Is-A Relationship (Inheritance):
Ø A class is a type of another class.
Ø Acquires the visible responsibility defined in super class.
Ø Define added responsibilities.
Has-A Relationship (Aggregation):
Ø Class contains another class (as member)
Ø Another class is part of the class
Uses-A Relationship (Association):
Ø Loosely coupled relationship
Ø A class interacts with another class
Ø Objects interacting with other objects. It may include
-Creation of another type of object
-Method invocation (Message passing) on already existing object
Polymorphism:
Ability of methods to share same name but different implementation
Ø Method overloading / Early Binding/ Compile time polymorphism.
Ø Method overriding /Late Binding/ Run time polymorphism.
Method overloading:
Ø Function Call mapped at compilation
Ø Class type and object type are the same
Ø Here the method call depends on the arguments passed to it.
Method overriding:
Ø Function Call mapped at run time
Ø Class type and object type need not to be same
Ø Here the method call depends on the object who is calling it.
No comments:
Post a Comment