What Is an Abstract Method?

Abstract methods in object-oriented programming languages are methods that have only method declarations and no specific method body. Abstract methods generally exist in abstract classes or interfaces.

Abstract method

This entry lacks an overview map . Supplementing related content makes the entry more complete and can be upgraded quickly. Come on!
Abstract methods in object-oriented programming languages are methods that have only method declarations and no specific method body. Abstract methods generally exist in
Abstract method:
Pure virtual functions and abstract classes:
A class containing pure virtual functions is an abstract class. Objects cannot be generated. They can only be derived. The pure virtual function of his derived class has not been rewritten, so its derived class is still an abstract class. The definition of pure virtual functions is to make the base class non-instantiable, because instantiating an abstract data structure does not make sense on its own, or it does not make sense to give an implementation
I. Pure virtual functions
In many cases, a meaningful virtual function definition cannot be given in the base class. At this time, it can be described as a pure virtual function, leaving its definition to the derived class. The general form of defining a pure virtual function is: class class name {virtual return value type function name (parameter table) = 0; // "= 0" after it is necessary, otherwise it becomes a virtual function}; pure virtual function It is a virtual function described in the base class. It is not defined in the base class and requires any derived class to define its own version. Pure virtual functions provide a common interface for derived classes. Pure virtual functions inherited from the base class are still virtual functions in derived classes.
2. Abstract Classes
1. If there is at least one pure virtual function in a class, the class is called an abstract class. Abstract classes include not only pure virtual functions, but also virtual functions. A pure virtual function in an abstract class may be defined in the abstract class, or it may be inherited and redefined from its abstract base class.
2. Abstract class characteristics, that is, the abstract class must be used as a base class derived from other classes, and cannot be used to directly create object instances. An abstract class cannot be used to create objects. It can only be used to provide an interface specification for the derived class. The derived class must overload the pure virtual function in the base class, otherwise it will still be regarded as an abstract class.
3. As mentioned in effective C ++, pure virtual functions can be implemented (defined), but object instances cannot be created, which also reflects the concept of abstract classes. (Source: Baidu Library, Author: dingxia0532)
Abstract method refers to a method without a method body. Specifically, there is no {} bracket and its content when the method is declared, but it is ended by adding a semicolon after the method name in the declaration.
Abstract methods do not have to implement specific functions. They are done by subclasses. Methods of abstract classes can have parameters or can be empty.
Abstract methods have the following characteristics:
1. Abstract methods are implicit virtual methods.
2. Only allow abstract method declarations in abstract classes.
3. Because the abstract method declaration does not provide a real implementation, there is no method body; the method declaration simply ends with a semicolon, and there are no braces ({}) after the signature. For example: public abstract void MyMethod ();
4. The abstract class must provide implementation for all interface members.
Questions about abstract classes and methods:
a. An abstract class can contain both abstract and non-abstract methods.
b. The purpose of an abstract method is to specify that a derived class must implement the behavior associated with this method.
c. Abstract methods are only really implemented in derived classes, which indicates that abstract methods only store function prototypes (return types of methods, names and parameters used), and do not involve body code.
d If the parent class is declared as an abstract class and there are unimplemented abstract methods, then the child class must implement all abstract members in the parent class, unless the class is also abstract. (From: CSDN, uploader:
Refers to the thought process of extracting common, essential attributes or characteristics of similar mathematical objects and discarding other non-essential attributes or characteristics. That is, the thinking method of extracting quantitative relationships or spatial forms from research objects or problems and discarding other attributes.
Several commonly used abstraction methods:
Equivalent abstraction
Take out the common attributes of similar research objects in thinking and discard other non-common attributes.
Idealized abstraction
It refers to the mathematical concepts and properties obtained through abstraction, not just the things that exist in objective things themselves, but the thought processes that are separated from the actual things, even hypothetical.
Possibility abstraction

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?