What is Abstraction in OOP?Abstraction is the concept of object-oriented programming that “shows” only essential attributes and “hides” unnecessary information. The main purpose of abstraction is hiding the unnecessary details from the users. Abstraction is selecting data from a larger pool to show only relevant details of the object to the user. It helps inreducing programming complexity and efforts. It is one of the most important concepts of OOPs.
You are watching: Data abstraction & problem solving with c++: walls and mirrors (7th edition) pdf
Click here if the video is not accessible
Let’s Study Abstraction in OOPs with example:
Suppose you want to create a banking application and you are asked to collect all the information about your customer. There are chances that you will come up with following information about the customer
Since we have fetched/removed/selected the customer information from a larger pool, the process is referred as Abstraction in OOPs.
However, the same information once extracted can be used for a wide range of applications. For instance, you can use the same data for hospital application, job portal application, a Government database, etc. with little or no modification. Hence, it becomes your Master Data. This is an advantage of Abstraction in OOPs.
Difference between Abstraction and Encapsulation
|Abstraction in Object Oriented Programming solves the issues at the design level.||Encapsulation solves it implementation level.|
|Abstraction in Programming is about hiding unwanted details while showing most essential information.||Encapsulation means binding the code and data into a single unit.|
|Data Abstraction in Java allows focussing on what the information object must contain||Encapsulation means hiding the internal details or mechanics of how an object does something for security reasons.|
Difference between Abstract Class and Interface
|An abstract class can have both abstract and non-abstract methods.||The interface can have only abstract methods.|
|It does not support multiple inheritances.||It supports multiple inheritances.|
|It can provide the implementation of the interface.||It can not provide the implementation of the abstract class.|
|An abstract class can have protected and abstract public methods.||An interface can have only have public abstract methods.|
|An abstract class can have final, static, or static final variable with any access specifier.||The interface can only have a public static final variable.|
What is Abstract Class?
Abstract Class is a type of class in OOPs, that declare one or more abstract methods. These classes can have abstract methods as well as concrete methods. A normal class cannot have abstract methods. An abstract class is a class that contains at least one abstract method.
What are Abstract Methods?
Abstract Method is a method that has just the method definition but does not contain implementation. A method without a body is known as an Abstract Method. It must be declared in an abstract class. The abstract method will never be final because the abstract class must implement all the abstract methods.
Advantages of AbstractionThe main benefit of using an Abstraction in Programming is that it allows you to group several related classes as siblings.Abstraction in Object Oriented Programming helps to reduce the complexity of the design and implementation process of software.
When to use Abstract Methods & Abstract Class?
Abstract methods are mostly declared where two or more subclasses are also doing the same thing in different ways through different implementations. It also extends the same Abstract class and offers different implementations of the abstract methods.
Abstract classes help to describe generic types of behaviors and object-oriented programming class hierarchy. It also describes subclasses to offer implementation details of the abstract class.
See more: Salvador Dali &Amp; I: The Surreal Story, Salvador Dali
Summary:Once you have modeled your object using Data Abstraction in Java, the same set of data could be used in different applications.