1.Topics‎ > ‎Architecture‎ > ‎

B.OOP Core Concepts

Fundamental OOPS Concepts

OOPs concepts are derived from our day to day exercises and activity, we can consolidate as below

Abstraction

    1. Hiding and summarized information
    2. Generally used for analyzing and modeling existing system

Encapsulation

    1. Process of putting related stuff under collective identity
    2. One of the way to achieve lowest level abstraction 
    3. In Programming world encapsulation if implemented by class definition. 
    4. 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 .
    5. Lay man View:- Binding or grouping  several things in such a way that they can exhibit a collective identity ,properties and behavior.

Inheritance

    1. In real world it is like Learning from older generation
    2. 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

    1. Summary
      1. In Real worlds it is like multiple personality which  Dynamic behavior based on surrounding
      2. It is an ability to exhibit either context or content dependent behavior by any entity.
      3. To implements context (compile time) or content (runtime) dependent behavior in programming arena that is very common with real world entities.
    2. Implantation Approach
      1. Single Dispatch (Virtual Function)
      2. Double Dispatch
      3. 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

  1. Design time: - Calls resolve at compile time by name mangling
  2. 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 ?

  1. Not Possible as compiler will always result error if attempted. However it is supported by CLR.
  2. Root Cause: Function Overloading is implemented by name decoration that does not take account of return type.
  3. 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

    1. Inter person communication

Extensibility 

    1. Ability to grow on demand 

Persistence

    1. Saving and restoring of states and information 

Delegation 

    1. Transferring the power or authority 

Genericity

    1. Commonly accepted solution 

Multiple Inheritance 

    1. Adapting characteristics  from multiple object from surrounding          

Special Considerations (Discussions )

 OOA Vs OOD

Object Oriented Analysis (OOA)  Object Oriented Analysis (OOD)
  1.  OOA is not a phase of an SDLC
  2.  OOA is really business disciplines of
    1.  Business Modeling
    2. Requirements
    3. Analysis
  3. OOA still implies “discovery” and “understanding”
  1. OOD is  phase in the SDLC
  2. OOD is a business disciplines  of 
    1. OOD is the bridge between Requirements and Programming
    2. OOD is a “developer” activity, not a user activity
    3. 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.
  1. Example  
    1. Aggregation (Assembling of Car from several parts)
    2. Composition (Preparation of Pizza from various ingredients)
  2. Aggregation is also known as a 'has a' relationship 
    1. 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.
    2. Example ('has a'): Room has a table and the table can exist without the room. The table can have meaning without the room also.
  3. Composition is also known as a 'is a part of' 
    1. 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.
    2. 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.
  4. Composition Example in Design Pattern : Design pattern like Facade uses composition 
  5. Aggregation Example in Design Pattern : Design pattern like service locator , strategy uses aggregation