{"id":1998,"date":"2019-05-27T21:00:04","date_gmt":"2019-05-27T18:00:04","guid":{"rendered":"http:\/\/demensdeum.com\/blog\/?p=1998"},"modified":"2024-12-16T22:32:37","modified_gmt":"2024-12-16T19:32:37","slug":"decorator-pattern","status":"publish","type":"post","link":"https:\/\/demensdeum.com\/blog\/ja\/2019\/05\/27\/decorator-pattern\/","title":{"rendered":"\u30d1\u30bf\u30fc\u30f3\u30c7\u30b3\u30ec\u30fc\u30bf\u30fc"},"content":{"rendered":"<p>Decorator \u30d1\u30bf\u30fc\u30f3\u306f\u3001\u69cb\u9020\u8a2d\u8a08\u30d1\u30bf\u30fc\u30f3\u3092\u6307\u3057\u307e\u3059\u3002<br \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2012\" src=\"https:\/\/demensdeum.com\/blog\/wp-content\/uploads\/2019\/05\/pexels-photo-348601.jpeg\" alt=\"\" width=\"380\" height=\"252\" \/><br \/>\n\u30c7\u30b3\u30ec\u30fc\u30bf\u306f\u3001\u30af\u30e9\u30b9\u306e\u6a5f\u80fd\u3092\u62e1\u5f35\u3059\u308b\u305f\u3081\u306e\u7d99\u627f\u306e\u4ee3\u66ff\u3068\u3057\u3066\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002<br \/>\u88fd\u54c1\u306e\u7a2e\u985e\u306b\u5fdc\u3058\u3066\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u6a5f\u80fd\u3092\u62e1\u5f35\u3059\u308b\u3068\u3044\u3046\u8ab2\u984c\u304c\u3042\u308a\u307e\u3059\u3002\u9867\u5ba2\u306f 3 \u7a2e\u985e\u306e\u88fd\u54c1\u3092\u5fc5\u8981\u3068\u3057\u3066\u3044\u307e\u3059\u3002\u30d9\u30fc\u30b7\u30c3\u30af\u3001\u30d7\u30ed\u30d5\u30a7\u30c3\u30b7\u30e7\u30ca\u30eb\u3001\u7a76\u6975\u3002<br \/>\u57fa\u672c&#8211;\u6587\u5b57\u6570\u3092\u30ab\u30a6\u30f3\u30c8\u3059\u308b\u3001Professional &#8211;\u6a5f\u80fd Basic + \u30c6\u30ad\u30b9\u30c8\u3092\u5927\u6587\u5b57\u3067\u5370\u5237\u3057\u307e\u3059\u3002Ultimate &#8211; Basic + Professional + \u7a76\u6975\u3068\u3044\u3046\u30c6\u30ad\u30b9\u30c8\u3092\u5370\u5237\u3057\u307e\u3059\u3002<br \/>\u7d99\u627f\u3092\u4f7f\u7528\u3057\u3066\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>protocol Feature {\n\tfunc textOperation(text: String)\n}\n\nclass BasicVersionFeature: Feature {\n\tfunc textOperation(text: String) {\n\t\tprint(\"\\(text.count)\")\n\t}\n}\n\nclass ProfessionalVersionFeature: BasicVersionFeature {\n\toverride func textOperation(text: String) {\n\t\tsuper.textOperation(text: text)\n\t\tprint(\"\\(text.uppercased())\")\n\t}\n}\n\nclass UltimateVersionFeature: ProfessionalVersionFeature {\n\toverride func textOperation(text: String) {\n\t\tsuper.textOperation(text: text)\n\t\tprint(\"ULTIMATE: \\(text)\")\n\t}\n}\n\nlet textToFormat = \"Hello Decorator\"\n\nlet basicProduct = BasicVersionFeature()\nbasicProduct.textOperation(text: textToFormat)\n\nlet professionalProduct = ProfessionalVersionFeature()\nprofessionalProduct.textOperation(text: textToFormat)\n\nlet ultimateProduct = UltimateVersionFeature()\nultimateProduct.textOperation(text: textToFormat)\n<\/code><\/pre>\n<\/div>\n<p>\u3053\u3053\u3067\u3001\u88fd\u54c1\u300cUltimate Light\u300d&#8211; \u3092\u5b9f\u88c5\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 Basic + Ultimate \u3067\u3059\u304c\u3001Professional \u30d0\u30fc\u30b8\u30e7\u30f3\u306e\u6a5f\u80fd\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u6700\u521d\u306e OH! \u304c\u8d77\u3053\u308b\u304b\u3089\u3067\u3059\u3002\u3053\u306e\u3088\u3046\u306a\u5358\u7d14\u306a\u30bf\u30b9\u30af\u7528\u306b\u5225\u306e\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u3001\u30b3\u30fc\u30c9\u3092\u8907\u88fd\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\u7d99\u627f\u3092\u4f7f\u7528\u3057\u3066\u5b9f\u88c5\u3092\u7d9a\u3051\u307e\u3057\u3087\u3046:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>protocol Feature {\n\tfunc textOperation(text: String)\n}\n\nclass BasicVersionFeature: Feature {\n\tfunc textOperation(text: String) {\n\t\tprint(\"\\(text.count)\")\n\t}\n}\n\nclass ProfessionalVersionFeature: BasicVersionFeature {\n\toverride func textOperation(text: String) {\n\t\tsuper.textOperation(text: text)\n\t\tprint(\"\\(text.uppercased())\")\n\t}\n}\n\nclass UltimateVersionFeature: ProfessionalVersionFeature {\n\toverride func textOperation(text: String) {\n\t\tsuper.textOperation(text: text)\n\t\tprint(\"ULTIMATE: \\(text)\")\n\t}\n}\n\nclass UltimateLightVersionFeature: BasicVersionFeature {\n\toverride func textOperation(text: String) {\n\t\tsuper.textOperation(text: text)\n\t\tprint(\"ULTIMATE: \\(text)\")\t\n\t}\n}\n\nlet textToFormat = \"Hello Decorator\"\n\nlet basicProduct = BasicVersionFeature()\nbasicProduct.textOperation(text: textToFormat)\n\nlet professionalProduct = ProfessionalVersionFeature()\nprofessionalProduct.textOperation(text: textToFormat)\n\nlet ultimateProduct = UltimateVersionFeature()\nultimateProduct.textOperation(text: textToFormat)\n\nlet ultimateLightProduct = UltimateLightVersionFeature()\nultimateLightProduct.textOperation(text: textToFormat)\n<\/code><\/pre>\n<\/div>\n<p>\u308f\u304b\u308a\u3084\u3059\u304f\u3059\u308b\u305f\u3081\u306b\u3053\u306e\u4f8b\u3092\u3055\u3089\u306b\u767a\u5c55\u3055\u305b\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u304c\u3001\u7d99\u627f\u30d9\u30fc\u30b9\u306b\u57fa\u3065\u3044\u3066\u30b7\u30b9\u30c6\u30e0\u3092\u30b5\u30dd\u30fc\u30c8\u3059\u308b\u8907\u96d1\u3055\u306f\u4eca\u3067\u3082\u660e\u3089\u304b\u3067\u3059 &#8211;\u9762\u5012\u3067\u67d4\u8edf\u6027\u306b\u6b20\u3051<br \/> \u307e\u3059\u3002\u30c7\u30b3\u30ec\u30fc\u30bf\u306f\u6a5f\u80fd\u3092\u8aac\u660e\u3059\u308b\u4e00\u9023\u306e\u30d7\u30ed\u30c8\u30b3\u30eb\u3067\u3042\u308a\u3001\u6a5f\u80fd\u3092\u62e1\u5f35\u3059\u308b\u30c7\u30b3\u30ec\u30fc\u30bf \u30af\u30e9\u30b9\u306e\u5b50\u5177\u8c61\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3078\u306e\u53c2\u7167\u3092\u542b\u3080\u62bd\u8c61\u30af\u30e9\u30b9\u3067\u3059\u3002<br \/>\u30d1\u30bf\u30fc\u30f3\u3092\u4f7f\u7528\u3057\u3066\u4e0a\u8a18\u306e\u4f8b\u3092\u66f8\u304d\u76f4\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>protocol Feature {\n\tfunc textOperation(text: String)\n}\n\nclass FeatureDecorator: Feature {\n\tprivate var feature: Feature?\n\t\n\tinit(feature: Feature? = nil) {\n\t\tself.feature = feature\n\t}\n\t\n\tfunc textOperation(text: String) {\n\t\tfeature?.textOperation(text: text)\n\t}\n}\n\nclass BasicVersionFeature: FeatureDecorator {\n\toverride func textOperation(text: String) {\n\t\tsuper.textOperation(text: text)\n\t\tprint(\"\\(text.count)\")\n\t}\n}\n\nclass ProfessionalVersionFeature: FeatureDecorator {\n\toverride func textOperation(text: String) {\n\t\tsuper.textOperation(text: text)\n\t\tprint(\"\\(text.uppercased())\")\n\t}\n}\n\nclass UltimateVersionFeature: FeatureDecorator {\n\toverride func textOperation(text: String) {\n\t\tsuper.textOperation(text: text)\n\t\tprint(\"ULTIMATE: \\(text)\")\n\t}\n}\n\nlet textToFormat = \"Hello Decorator\"\n\nlet basicProduct = BasicVersionFeature(feature: UltimateVersionFeature())\nbasicProduct.textOperation(text: textToFormat)\n\nlet professionalProduct = ProfessionalVersionFeature(feature: UltimateVersionFeature())\nprofessionalProduct.textOperation(text: textToFormat)\n\nlet ultimateProduct = BasicVersionFeature(feature: UltimateVersionFeature(feature: ProfessionalVersionFeature()))\nultimateProduct.textOperation(text: textToFormat)\n\nlet ultimateLightProduct = BasicVersionFeature(feature: UltimateVersionFeature())\nultimateLightProduct.textOperation(text: textToFormat)\n<\/code><\/pre>\n<\/div>\n<p>\u3053\u308c\u3067\u3001\u3042\u3089\u3086\u308b\u7a2e\u985e\u306e\u88fd\u54c1\u306e\u30d0\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f &#8211;\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u8d77\u52d5\u6bb5\u968e\u3067\u7d50\u5408\u30bf\u30a4\u30d7\u3092\u521d\u671f\u5316\u3059\u308b\u3060\u3051\u3067\u5341\u5206\u3067\u3059\u3002\u4ee5\u4e0b\u306e\u4f8b\u306f\u3001Ultimate + Professional \u30d0\u30fc\u30b8\u30e7\u30f3\u306e\u4f5c\u6210\u3067\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>ultimateProfessionalProduct.textOperation(text: textToFormat)\n<\/code><\/pre>\n<\/div>\n<h3>\u30bd\u30fc\u30b9<\/h3>\n<p><a href=\"https:\/\/refactoring.guru\/ru\/design-patterns\/decorator\" target=\"_blank\" rel=\"noopener\">https:\/\/refactoring.guru\/ru\/design-patterns\/decorator <\/a><\/p>\n<h3>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h3>\n<p><a href=\"https:\/\/gitlab.com\/demensdeum\/patterns\" target=\"_blank\" rel=\"noopener\">https:\/\/gitlab.com\/demensdeum\/patterns<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Decorator \u30d1\u30bf\u30fc\u30f3\u306f\u3001\u69cb\u9020\u8a2d\u8a08\u30d1\u30bf\u30fc\u30f3\u3092\u6307\u3057\u307e\u3059\u3002 \u30c7\u30b3\u30ec\u30fc\u30bf\u306f\u3001\u30af\u30e9\u30b9\u306e\u6a5f\u80fd\u3092\u62e1\u5f35\u3059\u308b\u305f\u3081\u306e\u7d99\u627f\u306e\u4ee3\u66ff\u3068\u3057\u3066\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u88fd\u54c1\u306e\u7a2e\u985e\u306b\u5fdc\u3058\u3066\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u6a5f\u80fd\u3092\u62e1\u5f35\u3059\u308b\u3068\u3044\u3046\u8ab2\u984c\u304c\u3042\u308a\u307e\u3059\u3002\u9867\u5ba2\u306f 3 \u7a2e\u985e\u306e\u88fd\u54c1\u3092\u5fc5\u8981\u3068\u3057\u3066\u3044\u307e\u3059\u3002\u30d9\u30fc\u30b7\u30c3\u30af\u3001\u30d7\u30ed\u30d5\u30a7\u30c3\u30b7\u30e7\u30ca\u30eb\u3001\u7a76\u6975\u3002\u57fa\u672c&#8211;\u6587\u5b57\u6570\u3092\u30ab\u30a6\u30f3\u30c8\u3059\u308b\u3001Professional &#8211;\u6a5f\u80fd Basic + \u30c6\u30ad\u30b9\u30c8\u3092\u5927\u6587\u5b57\u3067\u5370\u5237\u3057\u307e\u3059\u3002Ultimate &#8211; Basic + Professional + \u7a76\u6975\u3068\u3044\u3046\u30c6\u30ad\u30b9\u30c8\u3092\u5370\u5237\u3057\u307e\u3059\u3002\u7d99\u627f\u3092\u4f7f\u7528\u3057\u3066\u5b9f\u88c5\u3057\u307e\u3059\u3002 protocol Feature { func textOperation(text: String) } class BasicVersionFeature: Feature { func textOperation(text: String) { print(&#8220;\\(text.count)&#8221;) } } class ProfessionalVersionFeature: BasicVersionFeature { override func textOperation(text: String) { super.textOperation(text: text) print(&#8220;\\(text.uppercased())&#8221;) } } class UltimateVersionFeature: ProfessionalVersionFeature { override func textOperation(text: String)<a class=\"more-link\" href=\"https:\/\/demensdeum.com\/blog\/ja\/2019\/05\/27\/decorator-pattern\/\">Continue reading <span class=\"screen-reader-text\">&#8220;\u30d1\u30bf\u30fc\u30f3\u30c7\u30b3\u30ec\u30fc\u30bf\u30fc&#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":[104,95],"class_list":["post-1998","post","type-post","status-publish","format-standard","hentry","category-techie","category-tutorials","tag-decorator","tag-patterns","entry"],"translation":{"provider":"WPGlobus","version":"3.0.2","language":"ja","enabled_languages":["en","ru","zh","de","fr","ja","pt"],"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}}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/posts\/1998","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=1998"}],"version-history":[{"count":22,"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/posts\/1998\/revisions"}],"predecessor-version":[{"id":3957,"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/posts\/1998\/revisions\/3957"}],"wp:attachment":[{"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/media?parent=1998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/categories?post=1998"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/tags?post=1998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}