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...
  • jsc0218
  • jsc0218
  • 2011年11月15日 16:05
  • 248

pure abstract class(什么是纯抽象类?)

下面是C++的创造者的回答,供你参考 Bjarne Stroustrup: 我在对人们解释这个问题的过程中遇到了很多问题,而且我也一直不能理解为什么让人们理解这个问题是如此困难。自C++出现那天起...

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

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

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

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

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

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

1     Expressions Because there are no guarantees for how the sign bit is handled, we strongly reco...

R6025 pure virtual function call

  • 2010年04月13日 11:03
  • 4.51MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Abstract Classes and Pure Virtual Functions
举报原因:
原因补充:

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