Simple way to understand Encapsulation and Abstraction

Abstraction is a process where you show only “relevant” data and “hide” unnecessary details of an object from the user. Consider your mobile phone, you just need to know what buttons are to be pressed to send a message or make a call, What happens when you press a button, how your messages are sent, how your calls are connected is all abstracted away from the user.

Encapsulation is the process of combining data and functions into a single unit called class. In Encapsulation, the data is not accessed directly; it is accessed through the functions present inside the class. In simpler words, attributes of the class are kept private and public getter and setter methods are provided to manipulate these attributes. Thus, encapsulation makes the concept of data hiding possible.

enter image description here

Source:

http://stackoverflow.com/questions/16014290/simple-way-to-understand-encapsulation-and-abstraction

What is abstraction?

Abstraction is the technique of hiding implementation. At it’s core there’s not much more to that answer. The bulk of meaning to abstraction come from how and why it is used.
It is used for the following scenarios
  • Reduce complexity. (Create a simple interface)
  • Allow for implementation to be modified without impacting its users.
  • Create a common interface to support polymorphism (treating all implementations of the abstracted layer the same.
  • Force users to extend the implementation rather than modify.
  • Support cross platform by changing the implementation per platform.