OOPS - Data Hiding, Abstraction, Encapsulation, Tightly encapsulation class

preview_player
Показать описание
OOPS
1. Data Hiding
2. Abstraction
3. Encapsulation
4. Tightly encapsulation class
5. Is-A relationship
6. Has-A relationship
7. Method Signature
8. Overloading
9. Overriding
10. Static control flow
11. Instance control flow
12. Constructor
13. Coupling
14. Cohesion
15. Type casting

Data Hiding-
Outside person can’t access our internal data directly or our internal data should not go out directly. This OOP feature is called data hiding. After validation outside person can access our internal data.
e.g. Gmail = Username and password is required to enter into inbox information.
a. By declaring data member (variable) as private we can achieve data hiding.

* The main advantage of data hiding is security.
* Recommended modifier for variable is private.

Abstraction:
Hiding internal implementation and just highlight the set of services we are offering is concept of Abstraction.
The main advantages of abstraction are:
1. Security - We can achieve security because we are not highlighting our internal implementation.
2. Easy enhancement - Without affecting outside person we can able to perform any type of changes in our internal system and hence enhancement will come easy.
3. Maintainability - It improve maintainability of the application.
4 It improve easiness to use our system.

By using interfaces and abstract classes we can implement abstraction.

Encapsulation:
The process of binding data and corresponding method into a single unit is nothing but Encapsulation.
E.g Class Student , data member + methods (behaviour)

If any component follows data hiding and abstraction such type of component is said to be Encapsulated component.
Encapsulation = data hiding + Abstraction

Example:
public class Account{
private double balance;
public double getBalance()
{
// Validation
return balance;
}
public void setBalance(double balance)
{
//validation
}
}

The main advantage of Encapsulation are:
1. We can achieve security
2. Enhancement become easy.
3. It improves maintainability of the application.

The main disadvantage of Encapsulation is it increases length of the code and slows down execution.

Tightly Encapsulated Class:
A class is said to be tightly Encapsulated if and only if each and every variable declared as private. Weather class contain corresponding getter and setter method are not weather this method declared as public or not this things we are not required to check.
Рекомендации по теме