Java's enjoy meta-mode (big talk design mode)

Source: Internet
Author: User
Tags iweb

The author seldom uses to enjoy the meta-mode, in the author's view, the use of the module to solve memory problems should be more, Java in our common string is to use the idea of the module to solve the memory problem

First look at the class diagram

Liar design mode-Class diagram

Look at the author's demo

/***/Publicinterface  IWeb    {publicvoid saymyself ();}
/***/Publicclassimplements     iweb{Private  String name;      Public Currentweb (String name) {        Super();         this. Name = name;    }    @Override    publicvoid  saymyself () {        System.out.println (name);}    }
/*** Website Factory*/ Public classWebfactory {Privatemap<string, iweb> WebMap =NewHashmap<>();  PublicIWeb Getweb (String key) {if(!Webmap.containskey (Key)) {Webmap.put (Key,NewCurrentweb (key)); }        returnWebmap.get (key); }     Public intGetwebcount () {returnwebmap.size (); }}
/*** Client*/ Public classTest { Public Static voidMain (string[] args) {Webfactory factory=Newwebfactory (); IWeb Web= Factory.getweb ("Blog Park");        Web.saymyself (); IWeb Web1= Factory.getweb ("Blog Park");        Web1.saymyself (); IWeb web2= Factory.getweb ("Space");        Web2.saymyself (); SYSTEM.OUT.PRINTLN (web==web1);    System.out.println (Factory.getwebcount ()); }}

The output result is

Blog Park Blog Park space true2

Enjoy meta-mode I use less, may not understand the depth. Hopefully the demo will help the reader.

Java's enjoy meta-mode (big talk design mode)

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.