C++ Programming:-
Abstraction and Encapsulation both are basic object oriented programming (OOP) concepts which permit you to implement real-world objects into programs and codes. While both go hand in hand, they're very different from one another . In simple terms, once you put various things together to make an entity, you really create an idea – an abstract. While both are technically inseparable, they have got literally nothing in common. It’s almost true that each encapsulation is an abstraction because they both hide something, however, they need their justifiable share of differences
What is Abstraction?
Abstracting is a basic OOP concept which focuses on just the relevant data of an object and hides all the irrelevant details which may or may not be for generic or specialized behavior. It hides the background details and emphasizes on the essential points to scale back complexity and increase efficiency. Basically, abstraction may be a programming tool to manage complexity. Abstraction focuses on ideas rather than events. It hides the small print on the planning level by providing functionality to the users. The resulting object also can be called an abstraction. The programmer makes sure the named entity will have all the essential aspects included and none of the irrelevant ones.
Let’s take a real-world example of abstraction. Let’s consider the case of a vehicle, which in this case is your vehicle. A mechanic tries to repair your car or let’s say a specific part of your car. Here, you're the user and you don’t want to urge into the specifics of your car or what part actually broke. You don’t actually care about those things; you just want your vehicle back in its original condition without worrying about the details. So, you really told the mechanic what you would like by segregating the implementation part. This is abstraction. You focused on the foremost essential thing, which is getting your car fixed, instead of that specialize in the specifics.
Difference between Abstraction and Encapsulation
What is Encapsulation?
Encapsulation is yet another OOP concept which binds data and functions into a single component while restricting access to some components. It’s one among the most fundamental concepts of OOP which wraps data and knowledge under one unit. In technical terms, encapsulation means hiding attributes to shield variables from outside access so that change in one part of an application won’t affect the other parts. On the contrary, by making the knowledge more open you’ll risk misuse of knowledge . It provides basic integrity to the info by protecting it from the surface world. In simple terms, it hides the extra details from the outside world.
Let’s take an example of a Bluetooth mouse. You only got to realize the device’s behavior without fear about the implementation details like what quite sensors the mouse has, is it wireless or not, etc. Every single detail describes the mouse but regardless of the details, it’s just a mouse. You just need an interface to use the mouse, which in this case is the mouse pointer. This is encapsulation.
Difference between Abstraction and Encapsulation
While both are fundamental concepts related to OOP and they are technically inseparable, they still have their differences in many aspects.
Differences in “ Definition” of Abstraction and Encapsulation – Abstraction is a fundamental OOP concept which emphasizes on all the essential aspects of an object by hiding the irrelevant details to increase efficiency and eliminate complexity. Encapsulation, on the opposite hand, may be a data hiding mechanism which wraps the info and knowledge during a capsule to limit access from outside world.
Differences in “Functionality” of Abstraction and Encapsulation– Abstraction is a data hiding mechanism which highlights only the essential features to make complex programs simpler, while encapsulation, on the other hand, is a method of binding data and codes into one entity. The idea is to shield the implementation details from external access.
Differences in “Implementation” of Abstraction and Encapsulation – Abstraction is implemented using abstract class and interface, while encapsulation is implemented using access modifiers. Five sorts of modifiers are wont to encapsulate data: Private, Public, Internal, Protected, and guarded Internal.
Differences in “Concept” of Abstraction and Encapsulation– The idea behind abstraction is to focus on what rather than how. Encapsulation hides the internal mechanics of how. For example, once you drive a car, you recognize exactly what the pedal does but you'll not know the entire mechanism behind it because the info is encapsulated.
Differences in “Example” of Abstraction and Encapsulation – Let’s take an example of a smartphone. You know what it does but you may not know how it does what it does. You only care about the monitor and keypad buttons instead of worrying about its inner circuitry. Here, smartphone is an abstract where the inner implementation details are encapsulated.
0 comments:
Post a Comment
If you have any doubt, please let me know