Pattern of Eagle in Java design mode

Source: Internet
Author: User

http://www.verejava.com/?id=16999120847970

Package Com.flyweight.theory;public class testchess{public static void Main (string[] args) {Chess black1=ch                Essfactory.getchess ("Black Chess");                        Chess black2=chessfactory.getchess ("Black Chess");                Chess white1=chessfactory.getchess ("White Chess");    System.out.println (Chessfactory.getsize ()); }}package com.flyweight.theory;import Java.util.hashmap;import Java.util.map;public class ChessFactory{private        Static map<string,chess> map=new hashmap<string,chess> ();    public static int GetSize () {return map.size ();        } public static Chess getchess (String key) {Chess chess=null;            if (Map.get (key) ==null) {chess=new chess (key);        Map.put (key, chess);        } else {chess=map.get (key);    } return chess;    }}package Com.flyweight.theory;public class chess{private int x, y;        Private String type;   Public Chess (String type) {     Super ();    This.type = type;    } public int GetX () {return x;    } public void SetX (int x) {this.x = x;    } public int GetY () {return y;    } public void sety (int y) {this.y = y;    } public String GetType () {return type; }        }

http://www.verejava.com/?id=16999120847970

Pattern of Eagle in Java design mode

Related Article

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.