The terms of this section are relatively simple and popular means "there is one" and "is a" difference, and the difference between the application domain (application domain) and the implementation domain (implementation domain).
The following code:
1.
class Bird//鸟{public: //............};class ostrich:public Bird//鸵鸟{public: //............};
This code refers to the "is a" relationship, ostrich is also a bird, ostrich has a variety of bird properties.
2.
class Name{public: //..............};class Person{public: //.......private: Name name;};
This code refers to the "have a" relationship, the name is a class, everyone has a name.
3.
Take a look at the examples in the book:
#include <iostream>#include <list>using namespace STD;Template<classT>classmyset{Private: list<T>MyList; Public:intSize ()Const{returnMylist.size (); }BOOLiscontained (T Element)Const{return(Find (Mylist.begin (), Mylist.end (), T)! = Mylist.end ()); }BOOLInsert (T Element) {if(! Iscontained (T)) {mylist.push_back (Element);return true; }Else{return false; } }BOOLRemove (T Element) { list<T>:: Iterator Iter = Find (Mylist.begin (), Mylist.end (), T);if(Iter! = Mylist.end ()) {mylist.erase (Iter);return true; }Else{return false; } }};
This is the embodiment of the implementation of the domain, we are programmed to choose the structure of our program function to serve, so we have to transform the existing structure to adapt to our needs. As above, the list structure may store the same elements, but the set class requires that the same elements cannot be stored, so in order for the list structure to serve our program, we define the list operation in the program to meet our needs.
Effective C + + clause 38