关闭

Abstract Classes and Pure Virtual Functions

标签: classfeaturesinterfaceobjectapplicationforms
786人阅读 评论(0) 收藏 举报

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.

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:158796次
    • 积分:2764
    • 等级:
    • 排名:第13058名
    • 原创:117篇
    • 转载:30篇
    • 译文:0篇
    • 评论:8条
    文章分类
    最新评论