interface inheritance and implementation inheritance

Source: Internet
Author: User
Before you understand this concept, you need to understand a few concepts. Pure virtual function, virtual function, non-virtual function
Pure virtual functions: Classes declared as pure virtual functions must be used as base classes, classes containing pure virtual functions are called abstract classes, and abstract classes cannot instantiate objects. Therefore, pure virtual functions are generally used to declare interfaces. Its derived class must implement this function. Pure virtual functions can have function implementations in the base class, or they may not. The reason for declaring pure virtual functions is that the base class is often inappropriate for instantiation, such as the draw method in a shape class. Must be a pure virtual function, because he is not of any shape.
virtual function: A function declared in the base class as vitual and redefined in one or more derived classes. Virtual functions are used to provide a uniform name for a class of operations. Generally declared as virtual function is to implement polymorphism: Use the base class pointer to a derived class object, call the base class and the derived class with the same name function, call the method in the derived class (the premise vitual function is definitely implemented).
Non-virtual functions: General member functions, no virtual modifications. The derived class inherits the function interface and a mandatory implementation.
With these concepts, it is now explained that interface inheritance and implementation inheritance
Interface inheritance: Derived classes inherit only the function interface, which is the declaration. Implementing inheritance: Derived classes inherit both the interface and the implementation of the function.

Summary: When designing the class, follow the following points
  1. Pure virtual function: A function that requires a derived class to implement has no specific meaning in the base class.
  2. Virtual Functions: Inherited classes must contain interfaces that can be implemented either by themselves or not, and by the implementation of the base class.
  3. Non-virtual functions: An interface that inherits a class must function, and must be implemented using a base class.








From for notes (Wiz)

interface inheritance and implementation inheritance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.