Intrusive interface : You need to explicitly create a class to implement an interface .
Non intrusive interface : There is no need to explicitly create a class to implement an interface .
C++ Intrusive interface :
#include <iostream> enum SEX { MAIL, FEMAIL }; class PeopleInterface { public:
PeopleInterface(){}; virtual ~PeopleInterface(){}; virtual int getSex() = 0; };
class Man : public PeopleInterface { public: Man(){}; ~Man(){}; int getSex()
{return MAIL;} }; int main(int argc, char const *argv[]) { Man m;
std::cout<<"sex:"<<m.getSex()<<std::endl; return 0; }
go Non intrusive interface
package main import "fmt" type People interface { getSex() } type Man struct {
} func (m Man) getSex() int { return 0 } func main() { var m Man fmt.Println(
"sex:", m.getSex()) }
Want to implement an interface , Directly implement the methods contained in the interface , Don't worry too much about which method belongs to which interface .
Technology
Daily Recommendation