Home java abstraction in java

abstraction in java




I read about the OOP and it says that the OOP has 3 major basic concepts. This is encapsulation, polymorphism and inheritance.

also says that there is still an abstraction to them. I understood about the first three concepts, but about the abstraction, I don’t understand anything at all. Can you explain on what an example is an abstraction in the OOP? (Book: “Oo Analysis and Design”, Castle Boch).

In the first three concepts there is a specific application in the language, and I read about the abstraction only in theory and I do not understand why she and what is the meaning?

Answer 1, Authority 100%

Excellent question!
To understand what an abstraction can be read a couple of articles from the Internet (one Two ).

But in fact, it is enough to remember the following:

(abstraction will increase with each item)

Instance (object) The essence has a set of characteristics of the characteristic specific class instance. It has specific field values ​​(lower level, without abstraction)

class (class) Description of the set of objects similar by properties and internal structure (template for creating objects).

abstract class (abstract class) – an abstract description of the characteristics of a set of classes (acts as a template for inheritance by other classes). Has a high level of abstraction, in connection with which, from an abstract class you can not create objects directly * (only through the creation of objects from the classes of heirs)

Inside an abstract class may present methods with implementation
(but not necessarily)

4) interface (interface) is the design of the Java programming language, within which only abstract public methods can be described (Abstract Public) and static properties (Final Static). That is, as well as on the basis of abstract classes, it is impossible to generate objects based on interfaces.

UPD: Starting with Java 8 In addition to abstract methods and constants, we can also use standard methods in interfaces (Default Methods) and static methods (Static Methods).

A little about the implementation:

Classes in Java do not support multiple inheritance (this also applies to abstract classes), so can be inherited (directly), only from one parent:

class_name_name_naccount_name_Deller {
   // Sales

Needly class can implement multiple interfaces

class_name IMPLEMENTS interface_1, interface_2, ..., interface_n {
 // Implementation of interface methods
 // and the implementation of own methods

One interface can be a heir (can expand) multiple interfaces :

interface interface_1 Extends interface_2, interface_3, ..., interface_n {
  // Description of methods and fields for interface_1
  // also methods and fields will be taken from interface interfaces_2 ... interface_n

Classes can implement interfaces (i.e. receive from the interface list of methods and describe the implementation of each of them), moreover, it is especially important, one class can implement several interfaces :

class_name IMPLEMENTS interface_1, interface_2, ..., interface_n {
 // Implementation of interface methods
 // and the implementation of own methods

Class can directly inherit properties and methods, only from one parent class (extends ), and at the same time, it can implement multiple interfaces (Implements ):

class_name EXTENDS_Klass_2 IMPLEMENTS interface_1, interface_2, ..., interface_n {
 // Implementation of interface methods
 // Implementation of own methods
 // Override Parent Class Methods

output : since interface similar to the abstract class, but allows (implicit) to perform a multiple extension – it has a maximum level of abstraction

Answer 2, Authority 12%

For Java Abstraction is implemented using Abstract Class and Interface

Answer 3, Authority 12%

  1. Abstraction is a way we know how to interact with the outside world, to know it. We are thinking abstractions. We do not perceive the object always in all its complexity, but simplify it to the extent that the root situation requires. Dentistist, to whom the patient A.A.Ivanov came, is survived all early on a subtle mental organization and the comprehensive development of the personality A.A.Ivanov. A.A.Ivanov for him is the condition of the teeth, the reaction to the anasthesia and the number of monetary signs to pay for the service. Those. The abstraction is a separation of significant from insignificant in a particular context.

  2. above is about what is an abstraction in general. If you go down to java, then the abstraction is implemented in the form of abstract classes and interfaces. It is necessary for separating the interface (it sounds taftologically, but I can not formulate in a different way) from sales. This is necessary to reduce the association and increase the flexibility of the system.

  3. d In the principles of Solid and Indirection and Protected Variations in the GRASP patterns – this is all about abstraction and interfaces.

Answer 4, Authority 6%

Herbert Shildt answered this question well. While encapsulation, polymorphism and inheritance are the principles of the OOP, the abstraction is an element of the OOP. It stands above the principles of the OOP. The principles of the OOP are implemented by abstraction.
The abstraction in the context of the OOP is the main property of the class, which is to highlight important features in the context of the task and discarded the unimportant.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions