Remember:
- A good interface is easy to use correctly and is not easily misused. You should strive to achieve these properties in all of your interfaces.
- Ways to promote proper use include interface consistency and compatibility with built-in types of behavior.
- Ways to prevent misuse include creating new types, restricting operations on types, constraining object values, and eliminating customer resource management responsibilities.
- TR1::SHARED_PTR supports custom-made filters. This can be used to automatically unlock mutexes and so on.
classData { Public: Date (intMonthintDayintYear );;D Ate d ( -,3,1995);//wrong, it should be 3,30.structDay {ExplicitDay (intD): Val (d) {}intVal;};structMonth {ExplicitMonth (intm): Val (m) {}intVal;};structYear {ExplicitYear (inty): Val (y) {}intVal;};classDate { Public: Date (Constmonth& m,Constday& D,Constyear&y); ...};D ate d ( -,3,1995);//error, incorrect data typeDate D (Day ( -), Month (3), Year (1995));//error, incorrect data typeDate D (Month (3), Day ( -), Year (1995));//correct
class Month {public: staticreturn Month (1);} Static return Month (2);} ... Private : Explicit Month (int m);;D Ate d (Month::mar (), Day (+), year (1995));
Effective C + + clause 18: Make the interface easy to use correctly, not easy to misuse