zoukankan      html  css  js  c++  java
  • 什么是协议类

    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接口。(说抽象类相当于接口有点牵强,但说协议类相当于接口勉强可以接受,呵呵。)

  • 相关阅读:
    国庆·生日
    国足
    Eason's concert
    今天的斩获
    The 4400
    闷热
    24
    一直登录不了。。。原来是因为。。。
    黄色暴雨警告
    绝密飞行
  • 原文地址:https://www.cnblogs.com/helloweworld/p/3107173.html
Copyright © 2011-2022 走看看