{"id":2183,"date":"2019-09-16T23:45:51","date_gmt":"2019-09-16T20:45:51","guid":{"rendered":"http:\/\/demensdeum.com\/blog\/?p=2183"},"modified":"2024-12-16T22:32:34","modified_gmt":"2024-12-16T19:32:34","slug":"composite-pattern","status":"publish","type":"post","link":"https:\/\/demensdeum.com\/blog\/ja\/2019\/09\/16\/composite-pattern\/","title":{"rendered":"\u30d1\u30bf\u30fc\u30f3\u30b3\u30f3\u30dd\u30b8\u30c3\u30c8"},"content":{"rendered":"<p>\u8907\u5408\u30d1\u30bf\u30fc\u30f3\u306f\u69cb\u9020\u8a2d\u8a08\u30d1\u30bf\u30fc\u30f3\u3092\u6307\u3057\u3001\u56fd\u5185\u60c5\u5831\u6e90\u3067\u306f\u300c\u30b3\u30f3\u30dd\u30b8\u30bf\u30fc\u300d\u3068\u3057\u3066\u77e5\u3089\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u958b\u767a\u3057\u3066\u3044\u308b\u3068\u3057\u307e\u3059\u3002\u5199\u771f\u30a2\u30eb\u30d0\u30e0\u3002\u30e6\u30fc\u30b6\u30fc\u306f\u30d5\u30a9\u30eb\u30c0\u30fc\u3092\u4f5c\u6210\u3057\u3001\u305d\u3053\u306b\u5199\u771f\u3092\u8ffd\u52a0\u3057\u305f\u308a\u3001\u305d\u306e\u4ed6\u306e\u64cd\u4f5c\u3092\u5b9f\u884c\u3057\u305f\u308a\u3067\u304d\u307e\u3059\u3002\u30d5\u30a9\u30eb\u30c0\u30fc\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u306e\u6570\u3001\u3059\u3079\u3066\u306e\u30d5\u30a1\u30a4\u30eb\u3068\u30d5\u30a9\u30eb\u30c0\u30fc\u306e\u5408\u8a08\u6570\u3092\u8868\u793a\u3059\u308b\u6a5f\u80fd\u306f\u5fc5\u305a\u5fc5\u8981\u3067\u3059\u3002<br \/>\u30c4\u30ea\u30fc\u3092\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3053\u3068\u306f\u660e\u3089\u304b\u3067\u3059\u304c\u3001\u30b7\u30f3\u30d7\u30eb\u3067\u4fbf\u5229\u306a\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3092\u5099\u3048\u305f\u30c4\u30ea\u30fc \u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3092\u5b9f\u88c5\u3059\u308b\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u3088\u3044\u3067\u3057\u3087\u3046\u304b?\u8907\u5408\u30d1\u30bf\u30fc\u30f3\u304c\u5f79\u306b\u7acb\u3061\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.flickr.com\/photos\/8586177@N03\/5075169756\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2185\" src=\"https:\/\/demensdeum.com\/blog\/wp-content\/uploads\/2019\/09\/tree-1.jpg\" alt=\"\" width=\"400\" height=\"423\" \/><\/a><\/p>\n<div class=\"\u5c5e\u6027\u60c5\u5831\">\n<p><a class=\"owner-name truncate\" title=\"\u30e0\u30fc\u30f3\u30c0\u30c3\u30af\u30b9\u306e\u30d5\u30a9\u30c8\u30b9\u30c8\u30ea\u30fc\u30e0\u3067\u30b7\u30fc\u30e9\u306b\u884c\u304f\" href=\"https:\/\/www.flickr.com\/photos\/aspis7\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-track=\"attributionNameClick\">\u30e0\u30fc\u30f3\u30c0\u30c3\u30af\u30b9\u3092\u7740\u305f\u30b7\u30fc\u30e9<\/a><\/p>\n<div id=\"yui_3_16_0_1_1568665128454_889\" class=\"view follow-view clear-float photo-attribution\">\u5fc5\u8981\u306a dataCount() \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8 \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30d5\u30a1\u30a4\u30eb\/\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u6570\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002\u30d1\u30bf\u30fc\u30f3\u306b\u5f93\u3063\u3066 Component \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3092\u5b9f\u88c5\u3059\u308b\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u8ffd\u52a0\/\u524a\u9664\u3067\u304d\u308b\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3092\u5099\u3048\u305f Directory \u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u306f Composite \u3067\u3059\u3002\u307e\u305f\u3001File \u30af\u30e9\u30b9\u3082\u4f5c\u6210\u3057\u307e\u3059\u3002\u3053\u306e\u30af\u30e9\u30b9\u3067\u306f\u3001\u5199\u771f\u30ab\u30fc\u30c9\u3067\u30d0\u30a4\u30c8\u3092\u4fdd\u5b58\u3057\u3001Component \u304b\u3089\u7d99\u627f\u3057\u3001dataCount \u3092\u901a\u3058\u3066 1 \u3092\u8fd4\u3057\u3001\u5199\u771f\u304c 1 \u679a\u3057\u304b\u306a\u3044\u3053\u3068\u3092\u793a\u3057\u307e\u3059\u3002<\/div>\n<div>\u6b21\u306b\u3001\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b dataCount() \u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u88c5\u3057\u307e\u3059 &#8211;\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u914d\u5217\u306b\u3042\u308b\u3059\u3079\u3066\u306e\u8981\u7d20\u3092\u8abf\u3079\u3066\u3001\u305d\u308c\u3089\u306e dataCount \u3092\u3059\u3079\u3066\u5408\u8a08\u3057\u307e\u3059\u3002<\/div>\n<div>\u6e96\u5099\u306f\u5b8c\u4e86\u3067\u3059!<\/div>\n<div>\u4ee5\u4e0b\u306f Go \u306e\u4f8b\u3067\u3059\u3002<\/div>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>package main\n\nimport \"fmt\"\n\ntype component interface {\n\ndataCount() int\n\n}\n\ntype file struct {\n\n}\n\ntype directory struct {\n\nc []component\n\n}\n\nfunc (f file) dataCount() int {\n\nreturn 1\n\n}\n\nfunc (d directory) dataCount() int {\n\nvar outputDataCount int = 0\n\nfor _, v := range d.c {\noutputDataCount += v.dataCount()\n}\n\nreturn outputDataCount\n\n}\n\nfunc (d *directory) addComponent(c component) {\n\nd.c = append(d.c, c)\n\n}\n\nfunc main() {\n\nvar f file\nvar rd directory\nrd.addComponent(f)\nrd.addComponent(f)\nrd.addComponent(f)\nrd.addComponent(f)\n\nfmt.Println(rd.dataCount())\n\nvar sd directory\nsd.addComponent(f)\n\nrd.addComponent(sd)\nrd.addComponent(sd)\nrd.addComponent(sd)\n\nfmt.Println(sd.dataCount())\nfmt.Println(rd.dataCount())\n\n}\n<\/code><\/pre>\n<\/div>\n<h3>\u30bd\u30fc\u30b9<\/h3>\n<p><a href=\"https:\/\/refactoring.guru\/ru\/design-patterns\/composite\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/refactoring.guru\/ru\/design-patterns\/\u8907\u5408<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8907\u5408\u30d1\u30bf\u30fc\u30f3\u306f\u69cb\u9020\u8a2d\u8a08\u30d1\u30bf\u30fc\u30f3\u3092\u6307\u3057\u3001\u56fd\u5185\u60c5\u5831\u6e90\u3067\u306f\u300c\u30b3\u30f3\u30dd\u30b8\u30bf\u30fc\u300d\u3068\u3057\u3066\u77e5\u3089\u308c\u3066\u3044\u307e\u3059\u3002\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u958b\u767a\u3057\u3066\u3044\u308b\u3068\u3057\u307e\u3059\u3002\u5199\u771f\u30a2\u30eb\u30d0\u30e0\u3002\u30e6\u30fc\u30b6\u30fc\u306f\u30d5\u30a9\u30eb\u30c0\u30fc\u3092\u4f5c\u6210\u3057\u3001\u305d\u3053\u306b\u5199\u771f\u3092\u8ffd\u52a0\u3057\u305f\u308a\u3001\u305d\u306e\u4ed6\u306e\u64cd\u4f5c\u3092\u5b9f\u884c\u3057\u305f\u308a\u3067\u304d\u307e\u3059\u3002\u30d5\u30a9\u30eb\u30c0\u30fc\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u306e\u6570\u3001\u3059\u3079\u3066\u306e\u30d5\u30a1\u30a4\u30eb\u3068\u30d5\u30a9\u30eb\u30c0\u30fc\u306e\u5408\u8a08\u6570\u3092\u8868\u793a\u3059\u308b\u6a5f\u80fd\u306f\u5fc5\u305a\u5fc5\u8981\u3067\u3059\u3002\u30c4\u30ea\u30fc\u3092\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3053\u3068\u306f\u660e\u3089\u304b\u3067\u3059\u304c\u3001\u30b7\u30f3\u30d7\u30eb\u3067\u4fbf\u5229\u306a\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3092\u5099\u3048\u305f\u30c4\u30ea\u30fc \u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3092\u5b9f\u88c5\u3059\u308b\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u3088\u3044\u3067\u3057\u3087\u3046\u304b?\u8907\u5408\u30d1\u30bf\u30fc\u30f3\u304c\u5f79\u306b\u7acb\u3061\u307e\u3059\u3002 \u30e0\u30fc\u30f3\u30c0\u30c3\u30af\u30b9\u3092\u7740\u305f\u30b7\u30fc\u30e9 \u5fc5\u8981\u306a dataCount() \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8 \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30d5\u30a1\u30a4\u30eb\/\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u6570\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002\u30d1\u30bf\u30fc\u30f3\u306b\u5f93\u3063\u3066 Component \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3092\u5b9f\u88c5\u3059\u308b\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u8ffd\u52a0\/\u524a\u9664\u3067\u304d\u308b\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3092\u5099\u3048\u305f Directory \u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u306f Composite \u3067\u3059\u3002\u307e\u305f\u3001File \u30af\u30e9\u30b9\u3082\u4f5c\u6210\u3057\u307e\u3059\u3002\u3053\u306e\u30af\u30e9\u30b9\u3067\u306f\u3001\u5199\u771f\u30ab\u30fc\u30c9\u3067\u30d0\u30a4\u30c8\u3092\u4fdd\u5b58\u3057\u3001Component \u304b\u3089\u7d99\u627f\u3057\u3001dataCount \u3092\u901a\u3058\u3066 1 \u3092\u8fd4\u3057\u3001\u5199\u771f\u304c 1 \u679a\u3057\u304b\u306a\u3044\u3053\u3068\u3092\u793a\u3057\u307e\u3059\u3002 \u6b21\u306b\u3001\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b dataCount() \u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u88c5\u3057\u307e\u3059 &#8211;\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u914d\u5217\u306b\u3042\u308b\u3059\u3079\u3066\u306e\u8981\u7d20\u3092\u8abf\u3079\u3066\u3001\u305d\u308c\u3089\u306e dataCount \u3092\u3059\u3079\u3066\u5408\u8a08\u3057\u307e\u3059\u3002 \u6e96\u5099\u306f\u5b8c\u4e86\u3067\u3059! \u4ee5\u4e0b\u306f Go \u306e\u4f8b\u3067\u3059\u3002 package main import &#8220;fmt&#8221; type component interface { dataCount() int } type file struct { } type directory struct { c []component } func (f<a class=\"more-link\" href=\"https:\/\/demensdeum.com\/blog\/ja\/2019\/09\/16\/composite-pattern\/\">Continue reading <span class=\"screen-reader-text\">&#8220;\u30d1\u30bf\u30fc\u30f3\u30b3\u30f3\u30dd\u30b8\u30c3\u30c8&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[61,52],"tags":[116,95],"class_list":["post-2183","post","type-post","status-publish","format-standard","hentry","category-techie","category-tutorials","tag-composite","tag-patterns","entry"],"translation":{"provider":"WPGlobus","version":"3.0.2","language":"ja","enabled_languages":["en","ru","zh","de","fr","ja","pt","hi"],"languages":{"en":{"title":true,"content":true,"excerpt":false},"ru":{"title":true,"content":true,"excerpt":false},"zh":{"title":true,"content":true,"excerpt":false},"de":{"title":true,"content":true,"excerpt":false},"fr":{"title":true,"content":true,"excerpt":false},"ja":{"title":true,"content":true,"excerpt":false},"pt":{"title":true,"content":true,"excerpt":false},"hi":{"title":false,"content":false,"excerpt":false}}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/posts\/2183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/comments?post=2183"}],"version-history":[{"count":11,"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/posts\/2183\/revisions"}],"predecessor-version":[{"id":3944,"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/posts\/2183\/revisions\/3944"}],"wp:attachment":[{"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/media?parent=2183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/categories?post=2183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/tags?post=2183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}