An alternative to the Handle class approach is to make Person a special kind of abstract base class called a Protocol class. By
definition, a Protocol class has no implementation; its raison d'être is to specify an interface for derived classes (see Item 36).
As a result, it typically has no data members, no constructors, a virtual destructor (see Item 14), and a set of pure virtual
functions that specify the interface. A Protocol class for Person might look like this:
class Person {
public:
  virtual ~Person();
  virtual string name() const = 0;
  virtual string birthDate() const = 0;
  virtual string address() const = 0;
  virtual string nationality() const = 0;
};

 

简而言之,就是一种特殊的抽象类,特殊在哪里?抽象类可以有实现的部分,但是协议类完全没有实现,相当于java接口。(说抽象类相当于接口有点牵强,但说协议类相当于接口勉强可以接受,呵呵。)

相关文章:

  • 2021-05-10
  • 2021-06-07
  • 2021-11-25
  • 2021-07-14
  • 2022-01-11
  • 2022-01-04
  • 2021-06-24
猜你喜欢
  • 2021-06-25
  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
  • 2021-12-04
  • 2021-12-02
  • 2021-05-27
相关资源
相似解决方案