종우의 컴퓨터 공간
What is abstraction? 본문
What Is Abstraction?
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 unncessary 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 in reducing programming complexity and efforts.
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 Abstraction
· The main benefit of using an Abstraction in prigramming is that it allows you to group several related classes as siblings.
· Abstraction in OOP helps to reduce the complexity of the design and implementation process of software.
When to Use Abstract Methods & Abstract Classes?
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 OOP class hierarchy. It also describes subclasses to offer implementation details of the abstract class.
Differences between Abstraction and Encapsulation
Abstraction | Encapsulation |
Abstraction in OOP 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 |
We can implement Abstraction using abstraction class and interfaces | Whereas Encapsulation can be implemented using by accesss modifiers |
In Abstraction, implementation complexities are hidden using abstract classes and interfaces | While in Encapsulation, the data is hidden using methods of getters and setters |
Reference
https://www.guru99.com/java-data-abstraction.html
What is Abstraction in OOPs? Java Abstract Class & Method
Abstraction is selecting data from a larger pool to show only the relevant details to the object. In Java, abstraction is accomplished using Abstract classes and interfaces. It is one of the most important concepts of OOPs.
www.guru99.com
'Preparing Interviews > Object Oriented Programming' 카테고리의 다른 글
What is encapsulation? (0) | 2021.09.22 |
---|---|
What is Object Oriented Programming(OOP)? (0) | 2021.09.21 |