{"id":2764,"date":"2018-05-13T11:28:49","date_gmt":"2018-05-13T02:28:49","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=2764"},"modified":"2018-05-13T14:28:38","modified_gmt":"2018-05-13T05:28:38","slug":"%e3%80%90gof%e3%81%ae%e3%83%87%e3%82%b6%e3%82%a4%e3%83%b3%e3%83%91%e3%82%bf%e3%83%bc%e3%83%b3%e3%80%91%e3%80%8cflyweight%e3%80%8d%e3%81%a3%e3%81%a6%e3%81%a9%e3%82%93%e3%81%aa%e3%83%91%e3%82%bf","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=2764","title":{"rendered":"\u3010GoF\u306e\u30c7\u30b6\u30a4\u30f3\u30d1\u30bf\u30fc\u30f3\u3011\u300cFlyweight(\u30d5\u30e9\u30a4\u30a6\u30a7\u30a4\u30c8)\u300d\u3063\u3066\u3069\u3093\u306a\u30d1\u30bf\u30fc\u30f3\uff1f"},"content":{"rendered":"<h2>\u300cFlyweight(\u30d5\u30e9\u30a4\u30a6\u30a7\u30a4\u30c8)\u300d\u3063\u3066\u3069\u3093\u306a\u30d1\u30bf\u30fc\u30f3\uff1f<\/h2>\n<p>\u5c0f\u3055\u304f\u3066\u8efd\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u305f\u304f\u3055\u3093\u4f5c\u308a\u305f\u3044\u5834\u5408\u306b\u6709\u52b9\u306a\u30d1\u30bf\u30fc\u30f3\u3067\u3059\u3002<\/p>\n<h2>\u30e1\u30ea\u30c3\u30c8<\/h2>\n<p>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u751f\u6210\u3084\u3001\u4fdd\u6301\u306b\u5fc5\u8981\u306a\u30c8\u30fc\u30bf\u30eb\u306e\u8ca0\u8377\uff08\u30e1\u30e2\u30ea\uff09\u3092\u4e0b\u3052\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u5b9f\u969b\u306b\u306f\u3001Java\u306b\u306f\u3001<span style=\"color: #ff0000;\"><strong>\u300c\u30ac\u30fc\u30d9\u30b8\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u300d<\/strong><\/span>\u3068\u3044\u3046\u30e1\u30e2\u30ea\u3092\u81ea\u52d5\u3067\u89e3\u653e\u3059\u308b\u4ed5\u7d44\u307f\u304c\u3042\u308b\u306e\u3067\u3001<span style=\"color: #ff0000;\"><strong>\u305d\u308c\u307b\u3069\u30e1\u30e2\u30ea\u306b\u304a\u3044\u3066\u306f\u3001\u554f\u984c\u306b\u306a\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/strong><\/span><\/p>\n<p>\u305f\u3060\u3001\u3088\u308a\u30e1\u30e2\u30ea\u7ba1\u7406\u306e\u4e0a\u3067\u3082\u3001\u54c1\u8cea\u306e\u9ad8\u3044\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u308b\u3046\u3048\u3067\u306f\u3001\u77e5\u3063\u3066\u304a\u3044\u305f\u65b9\u304c\u3088\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<h2>\u5b9f\u969b\u306b\u5b9f\u88c5\u3057\u3066\u307f\u308b\u3002<\/h2>\n<p>\u5b9f\u88c5\u30a4\u30e1\u30fc\u30b8\u3068\u3057\u3066\u306f\u3001\u4e0b\u8a18\u306e\u30af\u30e9\u30b9\u56f3\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2772\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/Flywehgith_\u30af\u30e9\u30b9\u56f3.png\" alt=\"\" width=\"412\" height=\"365\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/Flywehgith_\u30af\u30e9\u30b9\u56f3.png 412w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/Flywehgith_\u30af\u30e9\u30b9\u56f3-300x266.png 300w\" sizes=\"(max-width: 412px) 100vw, 412px\" \/><\/p>\n<h3>Main.java(\u5b9f\u884c\u3059\u308b\u30d7\u30e9\u30b0\u30e9\u30e0\uff09<\/h3>\n<pre class=\"lang:default decode:true \">package flyweight;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void main(String[] args) {\r\n\r\n\t\tFullCousePool pool = new FullCousePool();\r\n\r\n\t\tFullCouse ordbul = pool.getCouse(\"\u524d\u83dc\", \"\u30b5\u30e9\u30c0\");\r\n\t\tSystem.out.println(ordbul);\r\n\t\tSystem.out.println(ordbul.kousei +\":\"+ordbul.name);\r\n\r\n\t\tFullCouse soup = pool.getCouse(\"\u524d\u83dc\", \"\u30b9\u30fc\u30d7\");\r\n\t\tSystem.out.println(soup);\r\n\t\tSystem.out.println(soup.kousei +\":\"+soup.name);\r\n\r\n\t\tFullCouse main1 = pool.getCouse(\"\u30e1\u30a4\u30f3\u30c7\u30a3\u30c3\u30b7\u30e5\", \"\u8089\u6599\u7406\");\r\n\t\tSystem.out.println(main1);\r\n\t\tSystem.out.println(main1.kousei +\":\"+main1.name);\r\n\r\n\t\tFullCouse main2 = pool.getCouse(\"\u30e1\u30a4\u30f3\u30c7\u30a3\u30c3\u30b7\u30e5\", \"\u9b5a\u6599\u7406\");\r\n\t\tSystem.out.println(main2);\r\n\t\tSystem.out.println(main2.kousei +\":\"+main2.name);\r\n\r\n\t}\r\n\r\n}\r\n<\/pre>\n<h3>FullCousePool.java(\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30d7\u30fc\u30eb\u3057\u3066\u304a\u304f\u30af\u30e9\u30b9\uff09<\/h3>\n<pre class=\"lang:default decode:true \">package flyweight;\r\n\r\nimport java.util.HashMap;\r\n\r\n\/**\r\n * \u30d5\u30eb\u30b3\u30fc\u30b9\u306e\u6599\u7406\u3092\u30d7\u30fc\u30eb\u3059\u308b\u30af\u30e9\u30b9\u3067\u3059\u3002\r\n *\/\r\npublic class FullCousePool {\r\n\r\n\tHashMap&lt;String,FullCouse&gt; dinnerPool = new HashMap&lt;&gt;();\r\n\r\n\tFullCouse getCouse(String kousei,String name) {\r\n\t\tFullCouse shareObj = (FullCouse)dinnerPool.get(kousei);\r\n\r\n\t\tif(shareObj==null) {\r\n\t\t\tshareObj = new FullCouse(kousei);\r\n\t\t\tdinnerPool.put(kousei, shareObj);\r\n\t\t}\r\n\r\n\t\tshareObj.name = name;\r\n\t\treturn shareObj;\r\n\r\n\t}\r\n\r\n\r\n}\r\n<\/pre>\n<h3>FullCouse.java(\u30d7\u30fc\u30eb\u3055\u308c\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09<\/h3>\n<pre class=\"lang:default decode:true \">package flyweight;\r\n\r\n\/**\r\n * \u30d5\u30eb\u30b3\u30fc\u30b9\u30af\u30e9\u30b9\u3067\u3059\u3002\r\n *\/\r\npublic class FullCouse {\r\n\r\n\tString name;\r\n\tString kousei;\r\n\r\n\tFullCouse(String kousei){\r\n\t\tthis.kousei = kousei;\r\n\t}\r\n\r\n}\r\n<\/pre>\n<h3>\u5b9f\u884c\u7d50\u679c<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2773\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/Flyweight.png\" alt=\"\" width=\"638\" height=\"216\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/Flyweight.png 638w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/Flyweight-300x102.png 300w\" sizes=\"(max-width: 638px) 100vw, 638px\" \/><\/p>\n<p>\u4f5c\u308a\u305f\u3044\u7a2e\u985e\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3054\u3068\u306b\u3001\u540c\u3058\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u4f7f\u3044\u307e\u308f\u3055\u308c\u308b\u5b9f\u88c5\u306b\u306a\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u306d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u300cFlyweight(\u30d5\u30e9\u30a4\u30a6\u30a7\u30a4\u30c8)\u300d\u3063\u3066\u3069\u3093\u306a\u30d1\u30bf\u30fc\u30f3\uff1f \u5c0f\u3055\u304f\u3066\u8efd\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u305f\u304f\u3055\u3093\u4f5c\u308a\u305f\u3044\u5834\u5408\u306b\u6709\u52b9\u306a\u30d1\u30bf\u30fc\u30f3\u3067\u3059\u3002 \u30e1\u30ea\u30c3\u30c8 \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u751f\u6210\u3084\u3001\u4fdd\u6301\u306b\u5fc5\u8981\u306a\u30c8\u30fc\u30bf\u30eb\u306e\u8ca0\u8377\uff08\u30e1\u30e2\u30ea\uff09\u3092\u4e0b\u3052\u308b\u3053\u3068\u304c\u3067\u304d\u307e [&hellip;]","protected":false},"author":1,"featured_media":2767,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,29,21],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2764"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2764"}],"version-history":[{"count":5,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2764\/revisions"}],"predecessor-version":[{"id":2774,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2764\/revisions\/2774"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/media\/2767"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2764"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}