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
Post a Comment