1. What is Oops Concepts?
=>Object Oriented programming is programming model where program are organized into objects and data rather then action and logic.
2. There are 4 Primary concepts of OOPs
=>Object Oriented programming is programming model where program are organized into objects and data rather then action and logic.
2. There are 4 Primary concepts of OOPs
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
- What is Abstraction?
Abstraction is used to hide implementation details and display some essential feature.
- Encapsulation:
- Encapsulation is used to hide data member and member function in single unit.
- Encapsulation is a way of encapsulating the data [wrapping the data] into a single unit called class.
- Class is the best example of encapsulation.
- Encapsulation is implemented by using access specifiers. An access specifier defines the scope and visibility of a class member. C# supports the following access specifiers.
- Public: Access Anywhere
- Private: Accesses inside the class
- Protected: Access inside the class or also access in the derived class.
- Internal: Access inside the assembly.(within Application)
- Protected internal: Access inside the assembly or derived object in the assembly
Real Life Example of Abstraction & Encapsulation:
Abstraction:
To implement abstraction let's take an example of a car. We knows a car, Car is made of name of car, color of car, steering, gear, rear view mirror, brakes, silencer, exhaust system, diesal engine, car battery, car engine and other internal machine details etc.
Now lets think in terms of Car rider or a person who is riding a car. So to drive a car what a car rider should know from above category before he starts a car driving.
Necessary things means compulsary to know before starting a car
1. Name of Car
2. Color of Car
3. Steering
4. Rear View Mirror
5. Brakes
6. Gear
Unnecessary things means not that compulsary to know for a Car rider
1. Internal Details of a Car
2. Car Engine
3. Diesal Engine
4. Exhaust System
5. Silencer
Encapsulation:
you have seen important TV machine, TV connections and TV color tube is hidden inside the TV case which is not been exposed for viewers like us and exposed only neccessary things of a TV like TV Channel keys, TV volume keys, ON/OFF switch, Cable Switch and TV remote control for viewers to use it.This means TV machine, TV connections and TV color tube is an unwanted data and not needed for viewers to see is been hidden from outside the world.
So encapsulation means hiding the important features of a class which is not been needed to be exposed outside of a class and exposing only necessary things of a class.
Abstraction | Encapsulation |
Abstraction solves the problem in the design level. | Encapsulation solves the problem in the implementation level. |
Abstraction is used for hiding the unwanted data and giving only relevant data. | Encapsulation is hiding the code and data into a single unit to protect the data from outer world. |
Abstraction is set focus on the object instead of how it does it. | Encapsulation means hiding the internal details or mechanics of how an object does something. |
Abstraction is outer layout in terms of design. For Example: - Outer Look of a iPhone, like it has a display screen. | Encapsulation is inner layout in terms of implementation. For Example: - Inner Implementation detail of a iPhone, how Display Screen are connect with each other using circuits |
Nice blogs.
ReplyDelete