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)