{"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\/ru\/2019\/05\/27\/decorator-pattern\/","title":{"rendered":"\u041f\u0430\u0442\u0442\u0435\u0440\u043d \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440"},"content":{"rendered":"<p>\u041f\u0430\u0442\u0442\u0435\u0440\u043d \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<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\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<br \/>\u0418\u043c\u0435\u0435\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430. \u0417\u0430\u043a\u0430\u0437\u0447\u0438\u043a\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0442\u0440\u0438 \u0442\u0438\u043f\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 &#8211; Basic, Professional, Ultimate.<br \/>Basic &#8211; \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, Professional &#8211; \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 Basic + \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0431\u0443\u043a\u0432\u0430\u043c\u0438, Ultimate &#8211; Basic + Professional + \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0441 \u043d\u0430\u0434\u043f\u0438\u0441\u044c\u044e ULTIMATE.<br \/>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f:<\/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>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0434\u0443\u043a\u0442 \u201cUltimate Light\u201d &#8211; Basic + Ultimate \u043d\u043e \u0431\u0435\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 Professional \u0432\u0435\u0440\u0441\u0438\u0438. \u0421\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u044b\u0439 \u041e\u0419!, \u0442.\u043a. \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438, \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434.<br \/>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f:<\/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>\u041f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u0438 \u0434\u0430\u043b\u044c\u0448\u0435, \u043d\u043e \u0443\u0436\u0435 \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u0432\u0438\u0434\u043d\u0430 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043d\u0430 \u0431\u0430\u0437\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f &#8211; \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u043e\u0441\u0442\u044c \u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438.<br \/>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u0441\u043e\u0432\u043e\u043a\u0443\u043f\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b, \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0433\u043e \u0440\u0435\u0444\u0435\u0440\u0435\u043d\u0441 \u043d\u0430 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b.<br \/>\u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0448\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430:<\/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>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 \u043b\u044e\u0431\u043e\u0433\u043e \u0442\u0438\u043f\u0430 &#8211; \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 Ultimate + Professional \u0432\u0435\u0440\u0441\u0438\u0438:<\/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>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438<\/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>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/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>\u041f\u0430\u0442\u0442\u0435\u0440\u043d \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.\u0418\u043c\u0435\u0435\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430. \u0417\u0430\u043a\u0430\u0437\u0447\u0438\u043a\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0442\u0440\u0438 \u0442\u0438\u043f\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 &#8211; Basic, Professional, Ultimate.Basic &#8211; \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, Professional &#8211; \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 Basic + \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0431\u0443\u043a\u0432\u0430\u043c\u0438, Ultimate &#8211; Basic + Professional + \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0442\u0435\u043a\u0441\u0442<a class=\"more-link\" href=\"https:\/\/demensdeum.com\/blog\/ru\/2019\/05\/27\/decorator-pattern\/\">Continue reading <span class=\"screen-reader-text\">&#8220;\u041f\u0430\u0442\u0442\u0435\u0440\u043d \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440&#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":"ru","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\/ru\/wp-json\/wp\/v2\/posts\/1998","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demensdeum.com\/blog\/ru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/demensdeum.com\/blog\/ru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/ru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/ru\/wp-json\/wp\/v2\/comments?post=1998"}],"version-history":[{"count":22,"href":"https:\/\/demensdeum.com\/blog\/ru\/wp-json\/wp\/v2\/posts\/1998\/revisions"}],"predecessor-version":[{"id":3957,"href":"https:\/\/demensdeum.com\/blog\/ru\/wp-json\/wp\/v2\/posts\/1998\/revisions\/3957"}],"wp:attachment":[{"href":"https:\/\/demensdeum.com\/blog\/ru\/wp-json\/wp\/v2\/media?parent=1998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/ru\/wp-json\/wp\/v2\/categories?post=1998"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/ru\/wp-json\/wp\/v2\/tags?post=1998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}