Abstraction vs Encapsulation.

           An OOP concept which focuses on relevant information by hiding unnecessary details.

          Abstraction hides complexity by giving more abstract picture, sort of 10000 feet view while Encapsulation hides internal working so that you can change it later. 

          Abstraction hides details at design level, while encapsulation hides details at implementation level. Its sole purpose is to hide the internal working of objects from the outside world so that you can change it later without impacting outside clients.

          Abstraction is about hiding unwanted details while giving out the most essential details, while encapsulation means hiding the code and data into a single unit e.g. class or method to protect the inner working of an object from the outside world.

(Abstraction can also be thought of as extracting common details or generalizing things).

          Abstraction lets you focus on what object does instead of how it does, while encapsulation means hiding the internal details of how an object works.

          In java, abstraction is supported using interface and abstract class  while encapsulation is supported using access modifiers e.g. public, private and protected.

           One example of abstraction is creating an interface to denote common behaviour without specifying any details about how that behaviour works like you create an interface called Server which has the start() and stop() method. This is called abstraction of Server  because every server should have a way to start and stop and details may differ from each other.

Comments

Popular posts from this blog

Priority Scheduling Algorithm Java Program.

Implement UNIX system calls like ps, fork, join, exec family, and wait for process management (use shell script/ Java/ C programming).

Implement a class CppArray which is identical to a one-dimensional C++ array (i.e., the index set is a set of consecutive integers starting at 0) except for the following : 1. It performs range checking. 2.It allows one to be assigned to another array through the use of assignment operator. 3.It supports a function that returns the size of the array.