design pattern--mixin modeCategory: Design&architecture 2011-09-09 15:27 322 people read Comments (0) Favorites Report design mode decorator class Java basic NULL adapter mode: Convert an interface to another interface.
Decorator mode: Dynamically adding functionality to an object. For example, the new Bufferedoutputstream (New FileOutputStream ("A-file-name")) in Java, Bufferedoutputstream adds buffer writing to FileOutputStream objects. This is the decorator mode.
Mixin mode: Generally speaking, it is to synthesize the functions of multiple classes to produce a class, but do not inherit more. The following is the implementation of a C + + mixin mode. Java with decorator can be implemented Mixin,java can also be implemented through dynamic Proxy (dynamics proxy) to achieve mixin, but it does not look as direct as C + +.[CPP] View Plain Copy// tst.cpp : defines the entry point for the console application. // /* result: 1314091501 1 1314091501 2 */ #include "stdafx.h" #include < iostream> #include <string> #include <time.h> using namespace std; class basic { public: long val; }; Template <class T> class timestamp: public t { private: long timestamp; public: timestamp () {& NBsp; timestamp=time (NULL); } long gettimestamp () { return timestamp; } }; template <class t> class serialnumbered: public T { private: long serialNumber; static long counter; public: serialnumbered () { serialnumber = ++ counter; } long getserialnumber () { return serialnumber; }