1.

What is Abstraction and Encapsulation?

Answer»
  • Abstraction

Abstraction means to show only the necessary details to the client of the object. Abstraction is the process of refining AWAY all the unneeded/unimportant attributes of an object and keep only the characteristics best suitable for your DOMAIN. Abstraction means putting all the variables and methods in a class which are necessary.

Encapsulation is a strategy used as part of abstraction. Encapsulation refers to the state of objects - objects encapsulate their state and hide it from the outside; outside users of the class interact with it through its methods, but cannot access the CLASSES state directly. So the class abstracts away the implementation details related to its state. It is a method for PROTECTING data from unwanted access or alteration. Encapsulation is the mechanism by which Abstraction is implemented.

Difference between Abstraction and Encapsulation

AbstractionEncapsulation
solves the problem in the design level.solves the problem in the implementation level.
hiding the unwanted data and giving only relevant data.hiding the code and data into a single unit to protect the data from outer world
set focus on the object instead of how it does ithiding the internal details or mechanics of how an object does something


Discussion

No Comment Found