In very short
Encapsulation:– Information hiding.
and Abstraction:– Implementation hiding.
Abstraction and Encapsulation both are OOP concepts of any object oriented programming languages which allow us to wrap real world things into classes and objects for using in the programming of application. Both Abstraction and Encapsulation in OOPs using hiding information to the world, so these are very confusing to understand the difference between each other for beginners.
So in very simple word I am telling you about Abstraction, it is nothing but it is one of the OOP concept which focuses on the process of hiding the unwanted details and exposing only the essential features of a particular object or concept, and Encapsulation is also one of the OOP concepts which also hides data from outside world but there are key differences between them to way of hiding data outside of world.
So what is different way of hiding data, that is, Abstraction hides complexity by giving you a more abstract picture of a complex system, For example, a class Car would be made up of an Engine, Gearbox, Steering objects, and many more components. To build the Car class, one does not need to know how the different components work internally, but only how to interface with them, i.e., send messages to them, receive messages from them, and perhaps make the different objects composing the class interact with each other, while Encapsulation hides internal working so that you can change it later, For example, all implementations and declaration related to the car wrap in the single unit called class i.e. Car class. In short we can say, Abstraction hides details at the design level, while Encapsulation hides details at the implementation level.
Suppose in above example, a class Car would be made up of an Engine, Gearbox, Steering objects, and many more components. When we first describe an object, you talk in more abstract term e.g. a Car has Engine, Gearbox, Steering objects but you don’t tell how to start engine, how to work Gearbox etc, Car will move, whether it will move by using tires or it will fly. It just moves. This is called Abstraction. We are talking about a most essential thing, which is moving, having engine, have gearbox etc rather than focusing on details of how to moving and starting engine.
In the programming, it is good practice to define different levels of Abstraction in the application and the classes should interact with other classes with the same level of abstraction or higher level of abstraction. As we increase the level of Abstraction, things start getting simpler and simpler because we leave out details.
In the OOP concept, Encapsulation is all about implementation. It wraps implementation and data into single unit, its purpose is to hide internal implementation of objects from outside world so that you can change this implementation later without impacting outside world.
Let’s see with example, in HashMap there are two very important method implementations put() and get() method. But developer only need to know hot put and get object to the HashMap instead how to work these implementation of HashMap internally. Because of Encapsulation, you can change the internal implementation of HashMap with ease without impacting clients who are using HashMap.
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…