OOPs concepts are derived from our day to day exercises and
activity, we can consolidate as below
Abstraction
- Hiding and summarized information
- Generally used for analyzing and modeling existing system
Encapsulation
- Process of putting related stuff under collective identity
- One of the way to achieve lowest level abstraction
- In Programming world encapsulation if implemented by class definition.
- Programmer View:- A Mechanism of binding both code and data together in order to unite and export them as single entity with well defined properties and behaviors .
- Lay man View:- Binding or grouping several things in such a way that they can exhibit a collective identity ,properties and behavior.
Inheritance
- In real world it is like Learning from older generation
- In programming world it is a process of importing properties and behavior of some other object or entity in order to build new one.
Polymorphism
- Summary
- In Real worlds it is like multiple personality which
Dynamic behavior based on surrounding
- It is an ability to exhibit either context or content dependent behavior by any entity.
- To implements context (compile time) or content (runtime) dependent behavior in programming arena that is very common with real world entities.
- Implantation Approach
- Single Dispatch (Virtual Function)
- Double Dispatch
- Multiple Dispatch
Types of Polymorphism
Compile (Desing) Time Polymorphism (Implemented through Static binding)
o Function overloading
o Operator overloading
Run Time Polymorphism (Implemented through Dynamic binding)
o Virtual and Override
o Interfaces Based Polymorphic implantation
o Configuration based Polymorphic implantation
Design Vs Run time polymorphism
- Design time: - Calls resolve at compile time by name mangling
- Runtime: - Calls resolve at run time either through dynamic binding or late binding using RTTI mechanism.
Need of Function Overloading
Function overloading is a way to implement contextual behavior in programming and is also a mechanism of achieving compile time polymorphism.
Overloading by Return Type ?
- Not Possible as compiler will always result error if attempted. However it is supported by CLR.
- Root Cause: Function Overloading is implemented by name decoration that does not take account of return type.
- Further Discussion: The CLR fully supports the ability for a type to define multiple methods that differ only by return type. But C# doesn't expose this ability to the C# programmer; the compiler does take advantage of this ability internally when a type defines conversion operator methods. This Feature are mostly used by compiler to implement Operator functions (OP_)
Messaging
- Inter person communication
Extensibility
- Ability to grow on demand
Persistence
- Saving and restoring of states and information
Delegation
- Transferring the power or authority
Genericity
- Commonly accepted solution
Multiple Inheritance
- Adapting characteristics from multiple object from surrounding
Special Considerations (Discussions )
OOA Vs OOD
Object Oriented Analysis (OOA) |
Object Oriented Analysis (OOD) |
- OOA is not a phase of an SDLC
- OOA is really business disciplines of
- Business Modeling
- Requirements
- Analysis
- OOA still implies “discovery” and “understanding”
| - OOD is phase in the SDLC
- OOD is a business disciplines of
- OOD is the bridge between Requirements and Programming
- OOD is a “developer” activity, not a user activity
- Few programs teach OOD – mostly we teach analysis and programming
|
Abstraction Vs Encapsulation
Encapsulation:-
1.
It is a process of binding of data and Behaviors
that operates on data in order to
provide them a single identity for Example Class Construct in Programming
Environment
2.
Deals with how to unite the elementary things to
give a collective identity
Abstraction:
1.
I is also a hiding approach that is used to hide
the complicity of the system .This is generally used to present the view of the
system that is useful from a particular prospective
2.
says how to export and use object service while
hiding the complexity of encapsulation
3.
It can also be seen as Hiding of implementation
details and exporting well defined set of services that allow the object to be
used as black box.
4.
When abstraction is applied to programming it
result to a process of building something new from pre-existing encapsulated
things for Example, User defined data type in programming construct.
5.
In BOOCH and OMT terminology it is defined as a
process that involve the selective study of the system
Abstraction Vs Data Abstraction
Abstraction is a vide concept and data abstraction is subset of it .In programming
arena data abstraction results to formulation of user defined Data type (UDT)
,also called Abstract Data type (ADT).These are data structures implemented
with the help of Class /and structure based encapsulation .
Aggregation Vs Delegation Vs Inheritance
- Delegation:-implements “has a”
relationship and serve the purpose of an alternative to inheritance in which
parent object invoke the services of child. In this relationship a class has
object of another class embedded in side.
- Aggregation:-Two or more classes combined to
create new one for example multiple inheritance (not supported in C#). We can
also see as composing or assembling activity in which we build new one using
multiple entities
- Inheritance: - It
is called “is a kind of” relations ship.
Example:- Suppose
we need to develop a software model for a set of cars. See the model to get clear.
Step-1:: Abstract the concept of car: - Car is a device that is
used for transport and have a Gear, Steering, Clutch, and Break . It can move
either backward or forward. It can also take turn either left or right
Step-2:: Encapsulate the elementary item of car:- In this step we encapsulate the
elementary car item i.e. Gearbox, Steering etc from basic data types
Step-3:: Apply Aggregation and Delegation to Assemble the CAR .At this stage
first car model will be ready.
Step-4:: Now apply inheritance to implement several model of
a car.
Aggregation Vs Composition
In normal terms, they both refer to member object but the survival or existence
of the member object without the containing class or object or after the
lifetime of the containing class or object makes the difference.- Example
- Aggregation (Assembling of Car from several parts)
- Composition (Preparation of Pizza from various ingredients)
- Aggregation is
also known as a 'has a' relationship
- because the containing object has a
member object and the member object can survive or exist without the enclosing
or containing class or can have a meaning after the lifetime of the enclosing
object also.
Example ('has a'): Room has a table and the table can exist without the
room. The table can have meaning without the room also.
- Composition is
also known as a 'is a part of'
- or 'is a' relationship because the member
object is a part of the containing class and the member object cannot
survive or exist outside the enclosing or containing class or doesnt have a
meaning after the lifetime of the enclosing object. Composition is used over
inheritance when different roles are to be played by a single entity. The 'is
a' relation comes in this case.
Example 1 ('is a part of'): Computer Science Department is a part of the
College. The Computer Science Department cannot exist without the college and
the department has no meaning after the lifetime of the college.
Composition Example in Design Pattern : Design pattern like Facade uses composition
- Aggregation Example in Design Pattern : Design pattern like service locator , strategy uses aggregation