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.
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
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
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.
4. PURE INTERFACES.
Definition in C++:
virtual void MemFun() = 0
MemFun is a pure interfaces, which has no implementation, but not alwaylse.