{"id":10505,"date":"2020-10-17T10:08:04","date_gmt":"2020-10-17T01:08:04","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=10505"},"modified":"2020-10-25T09:19:54","modified_gmt":"2020-10-25T00:19:54","slug":"command-%ed%8c%a8%ed%84%b4","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=10505","title":{"rendered":"[GoF] Command \ud328\ud134"},"content":{"rendered":"<h4>\ud328\ud134\uba85\uce6d<\/h4>\n<p>Command<\/p>\n<h4>\ud544\uc694\ud55c \uc0c1\ud669<\/h4>\n<p>\uc5b4\ub5a4 \uae30\ub2a5\uc774\ub098 \ub3d9\uc791\uc744 \uac1d\uccb4\ud654\ud558\uc5ec \uc2e4\ud589\ud560 \uc218 \uc788\ub294 \ud328\ud134\uc774\ub2e4. \uac1d\uccb4\ud654\ub41c \uae30\ub2a5\uc740 \uad00\ub9ac\ub418\uc5b4, \uc2e4\ud589\uc5d0 \ub300\ud55c Undo, Redo \uae30\ub2a5 \uad6c\ud604\uc774\ub098 \ubc30\uce58(Batch)\ub85c \ucc98\ub9ac\ub418\uc5b4 \uc5ec\ub7ec \uac1c\uc758 \uae30\ub2a5\uc744 \uc6d0\ud558\ub294 \uc2dc\uc810\uc5d0 \ud55c\ubc88\uc5d0 \uc2e4\ud589\ub420 \uc218 \uc788\ub2e4.<\/p>\n<h4>\uc608\uc81c \ucf54\ub4dc <\/h4>\n<p><img decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2020\/10\/command.png\" alt=\"\" width=\"800\"  class=\"aligncenter size-full wp-image-10506\" \/><\/p>\n<p>Command\ub294 \uc5b4\ub5a4 \uae30\ub2a5\uc774\ub098 \ub3d9\uc791\uc744 \uac1d\uccb4\ud654\ud558\uae30 \uc704\ud55c \uc778\ud130\ud398\uc774\uc2a4\uc774\ub2e4. \uc774 Command\ub97c \uad6c\ud604\ud558\ub294 \ud074\ub798\uc2a4\ub4e4\uc740 \uace0\uc720\ud55c \uae30\ub2a5\uc774\ub098 \ub3d9\uc791\uc744 \uc218\ud589\ud560 \uc218 \uc788\ub294 \uac1d\uccb4\ud654\uac00 \uac00\ub2a5\ud558\ub2e4. \uba3c\uc800 Command \uc778\ud130\ud398\uc774\uc2a4\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\npackage tstThread;\r\n\r\npublic interface Command {\r\n\tpublic void run();\r\n}\r\n<\/pre>\n<p>\ub2e4\uc74c\uc740 Command \uc778\ud130\ud398\uc774\uc2a4\ub97c \uad6c\ud604\ud558\ub294 CleanCommand\ub85c \ud654\uba74\uc744 \uc9c0\uc6b0\ub294 \uae30\ub2a5\uc744 \uc2e4\ud589\ud55c\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\npackage tstThread;\r\n\r\npublic class ClearCommand implements Command {\r\n\t@Override\r\n\tpublic void run() {\r\n\t\tSystem.out.print(\"\\033[H\\033[2J\");  \r\n\t    System.out.flush();  \r\n\t}\r\n}\r\n<\/pre>\n<p>\ub2e4\uc74c\uc740 PrintCommand\ub85c \ud654\uba74\uc5d0 \uc6d0\ud558\ub294 \ubb38\uc790\uc5f4\uc744 \ucd9c\ub825\ud558\ub294 \uae30\ub2a5\uc744 \uc2e4\ud589\ud55c\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\npackage tstThread;\r\n\r\npublic class PrintCommand implements Command {\r\n\tprivate String content;\r\n\t\r\n\tpublic PrintCommand(String content) {\r\n\t\tthis.content = content;\r\n\t}\r\n\t\r\n\t@Override\r\n\tpublic void run() {\r\n\t\tSystem.out.print(content);\r\n\t}\r\n}\r\n<\/pre>\n<p>\ub2e4\uc74c\uc740 MoveCommand\ub85c \ucd9c\ub825\ud560 \uc704\uce58\ub97c \uc9c0\uc815\ud558\ub294 \uae30\ub2a5\uc744 \uc2e4\ud589\ud55c\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\npackage tstThread;\r\n\r\npublic class MoveCommand implements Command {\r\n\tprivate int x;\r\n\tprivate int y;\r\n\t\r\n\tpublic MoveCommand(int x, int y) {\r\n\t\tthis.x = x;\r\n\t\tthis.y = y;\r\n\t}\r\n\t\r\n\t@Override\r\n\tpublic void run() {\r\n\t\tSystem.out.print(String.format(\"%c[%d;%df\", 0x1B, y, x));\r\n\t}\r\n}\r\n<\/pre>\n<p>\ub2e4\uc74c\uc740 TextColorCommand\ub85c \ubb38\uc790\uc5f4\uc744 \ucd9c\ub825\ud560\ub54c \uc0c9\uc0c1\uc744 \uc9c0\uc815\ud558\ub294 \uae30\ub2a5\uc744 \uc2e4\ud589\ud55c\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\npackage tstThread;\r\n\r\npublic class TextColorCommand implements Command {\r\n\tpublic enum Color {\r\n\t\tBLACK(\"\\u001B[30m\"), RED(\"\\u001B[31m\"), \r\n\t\tGREEN(\"\\u001B[32m\"), YELLOW(\"\\u001B[33m\"), BLUE(\"\\u001B[34m\"), \r\n\t\tPURPLE(\"\\u001B[35m\"), CYAN(\"\\u001B[36m\"), WHITE(\"\\u001B[37m\");\r\n\t\t\r\n\t\tfinal private String code; \r\n\t\t\r\n\t\tprivate Color(String name) { \r\n\t\t\tthis.code = name; \r\n\t\t} \r\n\t\t\r\n\t\tpublic String getCode() { \r\n\t\t\treturn code; \r\n\t\t}\r\n\t};\r\n\t\r\n\tprivate Color color;\r\n\t\r\n    public TextColorCommand(Color color) {\r\n    \tthis.color = color;\r\n    }\r\n    \r\n\t@Override\r\n\tpublic void run() {\r\n\t\tSystem.out.print(color.getCode());\r\n\t}\r\n}\r\n<\/pre>\n<p>\ub2e4\uc74c\uc740 BkColorCommand\ub85c \ubb38\uc790\uc5f4\uc744 \ucd9c\ub825\ud560\ub54c \ubc30\uacbd \uc0c9\uc0c1\uc744 \uc9c0\uc815\ud558\ub294 \uae30\ub2a5\uc744 \uc2e4\ud589\ud55c\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\npackage tstThread;\r\n\r\npublic class BkColorCommand implements Command {\r\n\tpublic enum Color {\r\n\t\tBLACK(\"\\u001B[40m\"), RED(\"\\u001B[41m\"), \r\n\t\tGREEN(\"\\u001B[42m\"), YELLOW(\"\\u001B[43m\"), BLUE(\"\\u001B[44m\"), \r\n\t\tPURPLE(\"\\u001B[45m\"), CYAN(\"\\u001B[46m\"), WHITE(\"\\u001B[47m\");\r\n\t\t\r\n\t\tfinal private String code; \r\n\t\t\r\n\t\tprivate Color(String name) { \r\n\t\t\tthis.code = name; \r\n\t\t} \r\n\t\t\r\n\t\tpublic String getCode() { \r\n\t\t\treturn code; \r\n\t\t}\r\n\t};\r\n\t\r\n\tprivate Color color;\r\n\t\r\n    public BkColorCommand(Color color) {\r\n    \tthis.color = color;\r\n    }\r\n    \r\n\t@Override\r\n\tpublic void run() {\r\n\t\tSystem.out.print(color.getCode());\r\n\t}\r\n}\r\n<\/pre>\n<p>\ub2e4\uc74c\uc740 MultiCommand\ub85c \uc5ec\ub7ec\uac1c\uc758 Command \uac1d\uccb4\ub97c \uc800\uc7a5\ud574 \ud55c\uaebc\ubc88\uc5d0 \uc2e4\ud589\ud558\ub294 \uae30\ub2a5\uc744 \uc2e4\ud589\ud55c\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\npackage tstThread;\r\n\r\nimport java.util.ArrayList;\r\n\r\npublic class MultiCommand implements Command {\r\n\tprivate ArrayList&lt;Command> commands = new ArrayList&lt;Command>();\r\n\t\r\n\tpublic void add(Command command) {\r\n\t\tcommands.add(command);\r\n\t}\r\n\t\r\n\t@Override\r\n\tpublic void run() {\r\n\t\tint cntCommands = commands.size();\r\n\t\tfor(int i=0; i&lt;cntCommands; i++) {\r\n\t\t\tCommand command = commands.get(i);\r\n\t\t\tcommand.run();\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>\uc9c0\uae08\uae4c\uc9c0\uc758 \ud074\ub798\uc2a4\ub97c \uc0ac\uc6a9\ud558\ub294 \uc608\uc81c \ucf54\ub4dc\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\npackage tstThread;\r\n\r\npublic class Main {\r\n\tpublic static void main(String[] args) {\r\n\t\tMultiCommand redTextWhiteBkColorCommand = new MultiCommand();\r\n\t\tredTextWhiteBkColorCommand.add(new TextColorCommand(TextColorCommand.Color.RED));\r\n\t\tredTextWhiteBkColorCommand.add(new BkColorCommand(BkColorCommand.Color.WHITE));\r\n\t\t\r\n\t\tMultiCommand blackTextGreenBkColorCommand = new MultiCommand();\r\n\t\tblackTextGreenBkColorCommand.add(new TextColorCommand(TextColorCommand.Color.BLACK));\r\n\t\tblackTextGreenBkColorCommand.add(new BkColorCommand(BkColorCommand.Color.GREEN));\r\n\t\t\r\n\t\tMultiCommand endCommand = new MultiCommand();\r\n\t\tendCommand.add(new TextColorCommand(TextColorCommand.Color.WHITE));\r\n\t\tendCommand.add(new BkColorCommand(BkColorCommand.Color.BLACK));\r\n\t\tendCommand.add(new MoveCommand(0, 24));\r\n\t\tendCommand.run();\r\n\t\t\r\n\t\tMultiCommand yellowTextRedBkColorCommand = new MultiCommand();\r\n\t\tyellowTextRedBkColorCommand.add(new TextColorCommand(TextColorCommand.Color.YELLOW));\r\n\t\tyellowTextRedBkColorCommand.add(new BkColorCommand(BkColorCommand.Color.RED));\r\n\t\t\r\n\t\tCommand clear = new ClearCommand();\r\n\t\tclear.run();\r\n\t\t\r\n\t\tredTextWhiteBkColorCommand.run();\r\n\t\t(new MoveCommand(10, 2)).run();\r\n\t\t(new PrintCommand(\"GIS\")).run();\r\n\t\t\r\n\t\tblackTextGreenBkColorCommand.run();\r\n\t\t(new MoveCommand(60, 4)).run();\r\n\t\t(new PrintCommand(\"Developer\")).run();\r\n\t\t\r\n\t\tyellowTextRedBkColorCommand.run();\r\n\t\t(new MoveCommand(30, 6)).run();\r\n\t\t(new PrintCommand(\"Dip2K\")).run();\r\n\t\t\r\n\t\tendCommand.run();\r\n\t}\r\n}\r\n<\/pre>\n<p>\uc2e4\ud589\uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2020\/10\/command2.png\" alt=\"\" width=\"800\" class=\"aligncenter size-full wp-image-10507\" \/><\/p>\n<div style='background:#efefef;border-radius:8px;padding:12px 24px'>\uc774 \uae00\uc740 \uc18c\ud504\ud2b8\uc6e8\uc5b4 \uc124\uacc4\uc758 \uae30\ubc18\uc774 \ub418\ub294 GoF\uc758 \ub514\uc790\uc778\ud328\ud134\uc5d0 \ub300\ud55c \uac15\uc758\uc790\ub8cc\uc785\ub2c8\ub2e4. \uc644\uc804\ud55c \uc2e4\uc2b5\uc744 \uc704\ud574 \uc774 \uae00\uc5d0\uc11c \uc18c\uac1c\ud558\ub294 \ud074\ub798\uc2a4 \ub2e4\uc774\uc5b4\uadf8\ub7a8\uacfc \uc608\uc81c \ucf54\ub4dc\ub294 \uc644\uc804\ud558\uac8c \uc2e4\ud589\ub418\ub3c4\ub85d \uc81c\uacf5\ub418\uc9c0\ub9cc, \uc0c1\ub300\uc801\uc73c\ub85c \uc608\uc81c \ucf54\ub4dc\uc640 \uad00\ub828\ub41c \uc124\uba85\uc774 \ud568\ucd95\uc801\uc73c\ub85c \uc81c\uacf5\ub418\uace0 \uc788\uc2b5\ub2c8\ub2e4. \uc774 \uae00\uc5d0 \ub300\ud574 \uad81\uae08\ud55c \uc810\uc774 \uc788\uc73c\uba74 \ub313\uae00\uc744 \ud1b5\ud574 \ub0a8\uaca8\uc8fc\uc2dc\uae30 \ubc14\ub78d\ub2c8\ub2e4.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\ud328\ud134\uba85\uce6d Command \ud544\uc694\ud55c \uc0c1\ud669 \uc5b4\ub5a4 \uae30\ub2a5\uc774\ub098 \ub3d9\uc791\uc744 \uac1d\uccb4\ud654\ud558\uc5ec \uc2e4\ud589\ud560 \uc218 \uc788\ub294 \ud328\ud134\uc774\ub2e4. \uac1d\uccb4\ud654\ub41c \uae30\ub2a5\uc740 \uad00\ub9ac\ub418\uc5b4, \uc2e4\ud589\uc5d0 \ub300\ud55c Undo, Redo \uae30\ub2a5 \uad6c\ud604\uc774\ub098 \ubc30\uce58(Batch)\ub85c \ucc98\ub9ac\ub418\uc5b4 \uc5ec\ub7ec \uac1c\uc758 \uae30\ub2a5\uc744 \uc6d0\ud558\ub294 \uc2dc\uc810\uc5d0 \ud55c\ubc88\uc5d0 \uc2e4\ud589\ub420 \uc218 \uc788\ub2e4. \uc608\uc81c \ucf54\ub4dc Command\ub294 \uc5b4\ub5a4 \uae30\ub2a5\uc774\ub098 \ub3d9\uc791\uc744 \uac1d\uccb4\ud654\ud558\uae30 \uc704\ud55c \uc778\ud130\ud398\uc774\uc2a4\uc774\ub2e4. \uc774 Command\ub97c \uad6c\ud604\ud558\ub294 \ud074\ub798\uc2a4\ub4e4\uc740 \uace0\uc720\ud55c \uae30\ub2a5\uc774\ub098 \ub3d9\uc791\uc744 \uc218\ud589\ud560 \uc218 \uc788\ub294 \uac1d\uccb4\ud654\uac00 \uac00\ub2a5\ud558\ub2e4. \uba3c\uc800 Command &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=10505\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;[GoF] Command \ud328\ud134&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-10505","post","type-post","status-publish","format-standard","hentry","category-design"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/10505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10505"}],"version-history":[{"count":5,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/10505\/revisions"}],"predecessor-version":[{"id":10554,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/10505\/revisions\/10554"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10505"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}