Abstract Classes and Pure Virtual Functions

原创 2006年05月18日 16:32:00

1. What is an Abstract Class?
Simply stated, an abstract class is a class which does not
fully represent an object. Instead, it represents a broad range of
different classes of objects. However, this representation
extends only to the features that those classes of objects have in
common. Thus, an abstract class provides only a partial
description of its objects.


Rumbaugh: “Abstract classes organize features
common to several classes.”

In C++, abstract class is the class that has pure virtual function.



Abstract class can be used to referred to sub class, eventhrough it is an incomplete
description of sub class.

Object is fixed, but under different context, the same object can have different features.

Lippman says: “[An abstract class] provides a common public interface for the entire
class hierarchy.”

The benefit of abstract:(Program to the interface, not to Implementation.)
By using the abstract as placehold, we can send request to sub object for the common feature.
1). Write less code.
2). Stable for change.

3. Designing Applications with Abstract Classes
The steps:
1) find out the concrete class that we need.
2) Spot common feature from the concrete classes.
  In a more complex application, commonality can be much
harder to detect. The names and forms of the methods can
disguise the intrinsic similarities. Thus, care should be exercised
in the search for commonality.
3) Factoring. (分解, 提升共有特征)
“Factor common responsibilities as high as possible.”

4) Evolution of concrete classes.

Definition in C++:

class cAbstract
  virtual void MemFun() = 0

MemFun is a pure interfaces, which has no implementation, but not alwaylse.


Pure Virtual Functions and Abstract Classes

Original Link:http://msdn.microsoft.com/en-us/library/aa273534(v=vs.60).aspxC++ Specific —>An abstra...
  • breeze_gao
  • breeze_gao
  • 2011年03月07日 13:21
  • 197

error C2253: 'RefCounted<T>' : pure specifier or abstract override specifier only allowed on virtual

环境:win7 32位,vs2010 源码: #include class RefCountedBase { public: void ref() { ++m_refCount; }...
  • dragoo1
  • dragoo1
  • 2015年05月07日 13:37
  • 1174

Pure Virtual Functions and Abstract Classes in C++

reference http://quiz.geeksforgeeks.org/pure-virtual-functions-and-abstract-classes/ 1) A class i...
  • u011028408
  • u011028408
  • 2017年04月20日 11:29
  • 194

C++ - 纯虚函数(pure virtual) 和 抽象基类(abstract base class)

纯虚函数(pure virtual) 和 抽象基类(abstract base class)   本文地址: http://blog.csdn.net/caroline_wendy   纯虚函数(pu...
  • u012515223
  • u012515223
  • 2013年11月13日 14:54
  • 3970


C++ 学习笔记之虚函数与纯虚函数
  • dbzhang800
  • dbzhang800
  • 2011年05月12日 23:56
  • 8576

【转载】一篇详尽分析C++“Pure Virtual Function Called”错误的文章

原文链接:http://www.artima.com/cppsource/pure_virtual.html   The C++ Source "Pure Virtual Function Ca...
  • u010665051
  • u010665051
  • 2013年09月21日 10:09
  • 1220

pure virtual method called

记录一个编写多线程程序时遇到的运行时错误:pure virtual method called 起因是写了一个多线程基类,里面有一个纯虚函数run,子类继承了这个run,重点就在纯虚函数上,因为是在...
  • freedomcheng
  • freedomcheng
  • 2014年12月26日 16:38
  • 1517

Some tips about Abstract base classes and pure virtual functions

  1、Often in a design, you want the base class to present only an interface for its derived classes,...
  • lconline
  • lconline
  • 2010年06月04日 22:49
  • 432

Python 2.7 Tutorial —— 类

.. _tut-classes: ******************Classes 类****************** Python's class mechanism adds classes...
  • ccat
  • ccat
  • 2010年10月05日 23:58
  • 2379

【C++基础】纯虚函数 - pure virtual function

1. 定义 在函数形参表后面写上 = 0 以指定纯虚函数. virtual void function() = 0;在派生类中必须实现(重写)该函数(不要后面的=0, 否则该派生来也不能实例化)....
  • robinjwong
  • robinjwong
  • 2014年02月10日 00:59
  • 1148
您举报文章:Abstract Classes and Pure Virtual Functions