Design mode--mixin Mode __ design mode

Source: Internet
Author: User
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;            }  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.