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.

2. STEREOTYPES And POLYMORPHISM.

stereotype
n.
固定形式;老一套

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.
Note:
  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.

4. PURE INTERFACES.
Definition in C++:

class cAbstract
{
private:
  virtual void MemFun() = 0
};

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

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Return to the Basic - 纯虚函数(pure virtual)和抽象类(abstract class)

纯虚函数(pure virtual function)是指在基类中声明但是没有定义的虚函数。 通用形式: virtual type func-name(parameter-list)=0; ...

Something about virtual function and pure virtual function

Firstly, let's demonstrate a fact that virtual function must be implemented. class A { public: A...

pure virtual function called--虚函数调用错误

参考:http://www.artima.com/cppsource/pure_virtual.html 前几天我们项目刚刚解决了一个pure virtual function call...

C++ pure virtual function call

最近在写代码的时候,遇到“pure virtual function call”的报错: 问题的背景是这样的,Thread是一个线程的基类,Thread的代码如下: #ifndef _THREAD...

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

原文链接:http://www.artima.com/cppsource/pure_virtual.html   The C++ Source "Pure Virtual Function Ca...

C++读书笔记之纯虚函数pure virtual function

In object-oriented programming, a virtual function or virtual method is a function or method whose b...

pure virtual function called--虚函数调用错误

最近一个项目自己设计了结构,练习使用了一下虚函数,在使用虚函数的时候就遇到了崩溃的问题,在网上查了一下,别人总结的,一起学习一下。。 一、理论上case 当一个纯虚函数被调用到时,vc++...

R6025 pure virtual function call

  • 2010-04-13 11:03
  • 4.51MB
  • 下载

《C++ Primer第五版》学习笔记(4)---expressions,statements,functions&classes

1     Expressions Because there are no guarantees for how the sign bit is handled, we strongly reco...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)