{"id":4071,"date":"2024-12-14T09:00:36","date_gmt":"2024-12-14T06:00:36","guid":{"rendered":"https:\/\/demensdeum.com\/blog\/2024\/12\/14\/dry-matters\/"},"modified":"2024-12-16T22:32:09","modified_gmt":"2024-12-16T19:32:09","slug":"dry-matters","status":"publish","type":"post","link":"https:\/\/demensdeum.com\/blog\/ja\/2024\/12\/14\/dry-matters\/","title":{"rendered":"DRY\u304c\u91cd\u8981\u306a\u7406\u7531"},"content":{"rendered":"<p>DRY \u306e\u30c8\u30d4\u30c3\u30af\u306b\u95a2\u3059\u308b\u8a18\u4e8b\u306f\u6570\u591a\u304f\u3042\u308a\u307e\u3059\u304c\u3001\u30aa\u30ea\u30b8\u30ca\u30eb\u306e\u30bd\u30fc\u30b9\u3067\u3042\u308b Andy Hunt \u3068 Dave Thomas \u306b\u3088\u308b\u300cThe Pragmatist Programmer\u300d\u3092\u8aad\u3080\u3053\u3068\u3092\u304a\u52e7\u3081\u3057\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u958b\u767a\u306b\u304a\u3051\u308b\u3053\u306e\u539f\u5247\u306b\u3064\u3044\u3066\u7591\u554f\u3092\u62b1\u3044\u3066\u3044\u308b\u958b\u767a\u8005\u304c\u3044\u304b\u306b\u591a\u3044\u304b\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n<p>DRY \u539f\u5247\u3067\u306f\u3001\u540c\u3058\u3053\u3068\u3092\u7e70\u308a\u8fd4\u3057\u3066\u306f\u3044\u3051\u306a\u3044\u3068\u5b9a\u3081\u3089\u308c\u3066\u304a\u308a\u3001\u3053\u308c\u306f\u30b3\u30fc\u30c9\u3068\u30d7\u30ed\u30b0\u30e9\u30de\u30fc\u3068\u3057\u3066\u5b9f\u884c\u3059\u308b\u30d7\u30ed\u30bb\u30b9\u306e\u4e21\u65b9\u306b\u5f53\u3066\u306f\u307e\u308a\u307e\u3059\u3002 DRY \u306b\u9055\u53cd\u3059\u308b\u30b3\u30fc\u30c9\u4f8b:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>class Client {\n    public let name: String\n    private var messages: [String] = []\n    \n    init(name: String) {\n        self.name = name\n    }\n    \n    func receive(_ message: String) {\n        messages.append(message)\n    }\n}\n\nclass ClientController {\n    func greet(client: Client?) {\n        guard let client else {\n            debugPrint(\"No client!\")\n            return\n        }\n        client.receive(\"Hello \\(client.name)!\")\n    }\n\n    func goodbye(client: Client?) {\n        guard let client else {\n            debugPrint(\"No client!!\")\n            return\n        }\n        client.receive(\"Bye \\(client.name)!\")\n    }\n}\n<\/code><\/pre>\n<\/div>\n<p>\u6328\u62f6\u30e1\u30bd\u30c3\u30c9\u3068\u5225\u308c\u306e\u30e1\u30bd\u30c3\u30c9\u3067\u308f\u304b\u308b\u3088\u3046\u306b\u3001Client \u30af\u30e9\u30b9\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u6e21\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u306f nil \u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u3001\u305d\u308c\u304b\u3089\u4f5c\u696d\u3092\u958b\u59cb\u3067\u304d\u307e\u3059\u3002 DRY \u30e1\u30bd\u30c3\u30c9\u306b\u6e96\u62e0\u3059\u308b\u306b\u306f\u3001\u30af\u30e9\u30b9 \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u91cd\u8907\u3057\u305f nil \u30c1\u30a7\u30c3\u30af\u3092\u524a\u9664\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306f\u3055\u307e\u3056\u307e\u306a\u65b9\u6cd5\u3067\u5b9f\u88c5\u3067\u304d\u307e\u3059\u30021 \u3064\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u3001\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u30af\u30e9\u30b9 \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u30fc\u306b\u6e21\u3059\u3053\u3068\u3067\u3001\u305d\u306e\u5f8c\u306f\u30c1\u30a7\u30c3\u30af\u304c\u5fc5\u8981\u306a\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>ClientController \u3092\u5358\u4e00\u306e Client \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u7279\u5316\u3059\u308b\u3053\u3068\u3067 DRY \u3092\u7dad\u6301\u3057\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>class Client {\n    public let name: String\n    private var messages: [String] = []\n    \n    init(name: String) {\n        self.name = name\n    }\n    \n    func receive(_ message: String) {\n        messages.append(message)\n    }\n}\n\nclass ClientController {\n    private let client: Client\n\n    init(client: Client) {\n        self.client = client\n    }\n\n    func greet() {\n        client.receive(\"Hello \\(client.name)!\")\n    }\n\n    func goodbye() {\n        client.receive(\"Bye \\(client.name)!\")\n    }\n}\n<\/code><\/pre>\n<\/div>\n<p>DRY \u306f\u3001\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u958b\u767a\u4e2d\u306b\u767a\u751f\u3059\u308b\u30d7\u30ed\u30bb\u30b9\u306b\u3082\u95a2\u4fc2\u3057\u307e\u3059\u3002\u958b\u767a\u30c1\u30fc\u30e0\u304c\u72ec\u81ea\u306b\u30ea\u30ea\u30fc\u30b9\u3092\u5e02\u5834\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u3001\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u958b\u767a\u304b\u3089\u6c17\u3092\u305d\u3089\u3055\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u72b6\u6cc1\u3092\u60f3\u50cf\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u3082 DRY \u9055\u53cd\u3067\u3059\u3002\u3053\u306e\u72b6\u6cc1\u306f\u3001\u958b\u767a\u8005\u304c\u6e80\u305f\u3059\u7279\u5b9a\u306e\u6761\u4ef6\u306b\u5f93\u3063\u3066\u3001\u30ea\u30ea\u30fc\u30b9\u304c\u81ea\u52d5\u7684\u306b\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u308b CI\/CD \u30d1\u30a4\u30d7\u30e9\u30a4\u30f3\u306b\u63a5\u7d9a\u3059\u308b\u3053\u3068\u3067\u89e3\u6c7a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u4e00\u822c\u306b\u3001DRY \u306f\u30d7\u30ed\u30bb\u30b9\u3068\u30b3\u30fc\u30c9\u306e\u4e21\u65b9\u306b\u7e70\u308a\u8fd4\u3057\u304c\u306a\u3044\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002\u3053\u308c\u306f\u4eba\u7684\u8981\u56e0\u306e\u5b58\u5728\u306b\u3088\u3063\u3066\u3082\u91cd\u8981\u3067\u3059\u3002\u7e70\u308a\u8fd4\u3057\u304c\u5c11\u306a\u304f\u30ce\u30a4\u30ba\u306e\u591a\u3044\u30b3\u30fc\u30c9\u304c\u542b\u307e\u308c\u308b\u30b3\u30fc\u30c9\u306f\u3001\u30a8\u30e9\u30fc\u306e\u30c1\u30a7\u30c3\u30af\u304c\u5bb9\u6613\u3067\u3059\u3002\u81ea\u52d5\u5316\u3055\u308c\u305f\u30d7\u30ed\u30bb\u30b9\u3067\u306f\u3001\u4eba\u9593\u304c\u95a2\u4e0e\u3057\u306a\u3044\u305f\u3081\u3001\u30d7\u30ed\u30bb\u30b9\u306e\u5b9f\u884c\u4e2d\u306b\u9593\u9055\u3044\u3092\u72af\u3059\u3053\u3068\u304c\u306a\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u30b9\u30c6\u30a3\u30fc\u30d6\u30fb\u30b8\u30e7\u30d6\u30ba\u306e\u683c\u8a00\u306f\u3001\u300c\u66f8\u304f\u5fc5\u8981\u306e\u306a\u304b\u3063\u305f\u30b3\u30fc\u30c9\u884c\u306f\u3001\u30c7\u30d0\u30c3\u30b0\u3059\u308b\u5fc5\u8981\u306e\u306a\u3044\u30b3\u30fc\u30c9\u884c\u3067\u3059\u3002\u300d\u3067\u3059\u3002<\/p>\n<h2>\u30bd\u30fc\u30b9<\/h2>\n<p><a href=\"https:\/\/pragprog.com\/titles\/tpp20\/the-pragmatic-programmer-20th-anniversary-edition\/\" rel=\"noopener\" target=\"_blank\">https:\/\/pragprog.com\/titles\/tpp20\/the-pragmatic-programmer-20th-anniversary-edition\/<\/a><br \/>\n<a href=\"https:\/\/youtu.be\/-msIEOGvTYM\" rel=\"noopener\" target=\"_blank\">https:\/\/youtu.be\/-msIEOGvTYM<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>DRY \u306e\u30c8\u30d4\u30c3\u30af\u306b\u95a2\u3059\u308b\u8a18\u4e8b\u306f\u6570\u591a\u304f\u3042\u308a\u307e\u3059\u304c\u3001\u30aa\u30ea\u30b8\u30ca\u30eb\u306e\u30bd\u30fc\u30b9\u3067\u3042\u308b Andy Hunt \u3068 Dave Thomas \u306b\u3088\u308b\u300cThe Pragmatist Programmer\u300d\u3092\u8aad\u3080\u3053\u3068\u3092\u304a\u52e7\u3081\u3057\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u958b\u767a\u306b\u304a\u3051\u308b\u3053\u306e\u539f\u5247\u306b\u3064\u3044\u3066\u7591\u554f\u3092\u62b1\u3044\u3066\u3044\u308b\u958b\u767a\u8005\u304c\u3044\u304b\u306b\u591a\u3044\u304b\u304c\u308f\u304b\u308a\u307e\u3059\u3002 DRY \u539f\u5247\u3067\u306f\u3001\u540c\u3058\u3053\u3068\u3092\u7e70\u308a\u8fd4\u3057\u3066\u306f\u3044\u3051\u306a\u3044\u3068\u5b9a\u3081\u3089\u308c\u3066\u304a\u308a\u3001\u3053\u308c\u306f\u30b3\u30fc\u30c9\u3068\u30d7\u30ed\u30b0\u30e9\u30de\u30fc\u3068\u3057\u3066\u5b9f\u884c\u3059\u308b\u30d7\u30ed\u30bb\u30b9\u306e\u4e21\u65b9\u306b\u5f53\u3066\u306f\u307e\u308a\u307e\u3059\u3002 DRY \u306b\u9055\u53cd\u3059\u308b\u30b3\u30fc\u30c9\u4f8b: class Client { public let name: String private var messages: [String] = [] init(name: String) { self.name = name } func receive(_ message: String) { messages.append(message) } } class ClientController { func greet(client: Client?) { guard let client else { debugPrint(&#8220;No<a class=\"more-link\" href=\"https:\/\/demensdeum.com\/blog\/ja\/2024\/12\/14\/dry-matters\/\">Continue reading <span class=\"screen-reader-text\">&#8220;DRY\u304c\u91cd\u8981\u306a\u7406\u7531&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","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":[49],"tags":[],"class_list":["post-4071","post","type-post","status-publish","format-standard","hentry","category-blog","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\/4071","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=4071"}],"version-history":[{"count":7,"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/posts\/4071\/revisions"}],"predecessor-version":[{"id":4078,"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/posts\/4071\/revisions\/4078"}],"wp:attachment":[{"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/media?parent=4071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/categories?post=4071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/ja\/wp-json\/wp\/v2\/tags?post=4071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}