{"id":10362,"date":"2020-10-05T08:21:42","date_gmt":"2020-10-04T23:21:42","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=10362"},"modified":"2020-10-25T09:21:43","modified_gmt":"2020-10-25T00:21:43","slug":"iterator-%ed%8c%a8%ed%84%b4","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=10362","title":{"rendered":"[GoF] Iterator \ud328\ud134"},"content":{"rendered":"<h4>\ud328\ud134\uba85\uce6d <\/h4>\n<p>Iterator<\/p>\n<h4>\ud544\uc694\ud55c \uc0c1\ud669 <\/h4>\n<p>\ubc30\uc5f4\uacfc \uac19\uc774 \ub3d9\uc77c\ud55c \ud615\ud0dc\uc758 \ub370\uc774\ud130\ub97c \uc5ec\ub7ec \uac1c \uc800\uc7a5\ud558\uace0 \uc788\ub294 \uc800\uc7a5\uc18c(Aggregator)\uac00 \uc788\ub2e4. \uc774 \uc800\uc7a5\uc18c\uc5d0 \uc800\uc7a5\ub41c \ub370\uc774\ud130\ub97c \uc21c\uc11c\ub300\ub85c \uc811\uadfc\ud558\uae30 \uc704\ud55c \ud328\ud134\uc774\ub2e4. \uc21c\uc11c\ub300\ub85c \uc811\uadfc\ud558\uae30 \uc704\ud55c \ubc29\ubc95\uc740 \uc800\uc7a5\uc18c\uc758 \uc885\ub958\uc640\ub294 \uc0c1\uad00\uc5c6\uc774 \ub3d9\uc77c\ud55c \ubc29\uc2dd(API)\uc744 \uc81c\uacf5\ud55c\ub2e4.<\/p>\n<h4>\uc608\uc81c \ucf54\ub4dc <\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2020\/10\/iterator2.png\" alt=\"\" width=\"694\" height=\"616\" class=\"aligncenter size-full wp-image-10367\" \/><\/p>\n<p>Aggregator\uc640 Iterator \uc778\ud130\ud398\uc774\uc2a4\ub294 \uc800\uc7a5\uc18c\uc758 \ud615\ud0dc\uc640 \uc885\ub958\uc5d0 \uc0c1\uad00\uc5c6\uc774 \uc800\uc7a5\uc18c\ub97c \uad6c\uc131\ud558\ub294 \ub370\uc774\ud130\ub97c \uc21c\ucc28\uc801\uc73c\ub85c \ubaa8\ub450 \uc811\uadfc\ud558\uae30 \uc704\ud55c API\ub97c \uc81c\uacf5\ud55c\ub2e4. \uc774 \uc778\ud130\ud398\uc774\uc2a4\ub97c \uad6c\uc131\ud558\ub294 Table\uacfc RowIterator\ub294 \uc800\uc7a5\uc18c\uc5d0 \ub300\ud55c \ud2b9\ud654\ub41c \uad6c\ud604 \ud074\ub798\uc2a4\uc774\ub2e4. Row \uc5ed\uc2dc \uc800\uc7a5\uc18c\ub97c \uad6c\uc131\ud558\ub294 \ud2b9\ud654\ub41c \ub370\uc774\ud130 \uad6c\uc870\uc5d0 \ub300\ud55c \ud074\ub798\uc2a4\uc774\ub2e4. \uc774\ub4e4 \ud074\ub798\uc2a4\ub97c \uc0ac\uc6a9\ud558\ub294 \uc608\uc81c\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\npackage pattern;\r\n\r\npublic class Main {\r\n\tpublic static void main(String[] args) {\r\n\t\tTable table = new Table();\r\n\t\t\r\n\t\ttable.add(new Row(\"Jane\", 27));\r\n\t\ttable.add(new Row(\"Suji\", 35));\r\n\t\ttable.add(new Row(\"Tom\", 19));\r\n\t\ttable.add(new Row(\"Robin\", 43));\r\n\t\ttable.add(new Row(\"Robert\", 58));\r\n\t\t\r\n\t\tIterator it = table.iterator();\r\n\t\twhile(it.next()) {\r\n\t\t\tRow row = (Row)it.current();\r\n\t\t\tSystem.out.println(row);\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>Aggregator \uc778\ud130\ud398\uc774\uc2a4\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\npackage pattern;\r\n\r\npublic interface Aggregator {\r\n\tIterator iterator();\r\n}\r\n<\/pre>\n<p>Itertor \uc778\ud130\ud398\uc774\uc2a4\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\npackage pattern;\r\n\r\npublic interface Iterator {\r\n\tboolean next();\r\n\tObject current();\r\n}\r\n<\/pre>\n<p>next\ub294 \ub2e4\uc74c \uad6c\uc131 \ub370\uc774\ud130\ub85c \uc774\ub3d9\ud558\uace0 true\ub97c \ubc18\ud658\ud55c\ub2e4. \ub9cc\uc57d \ub2e4\uc74c \ub370\uc774\ud130\uac00 \uc874\uc7ac\ud558\uc9c0 \uc54a\uc73c\uba74 false\ub97c \ubc18\ud658\ud55c\ub2e4. current\ub294 \ud604\uc7ac Itertor\uac00 \uac00\ub974\ud0a4\uace0 \uc788\ub294 \ud604\uc7ac\uc758 \ub370\uc774\ud130\ub97c \ubc18\ud658\ud55c\ub2e4. Aggregator\ub97c \uad6c\ud604\ud558\ub294 Table \ud074\ub798\uc2a4\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\npackage pattern;\r\n\r\nimport java.util.LinkedList;\r\n\r\npublic class Table implements Aggregator {\r\n\tprivate LinkedList&lt;Row> table = new LinkedList&lt;Row>();\r\n\t\r\n\tpublic Table() {\r\n\t\t\/\/.\r\n\t}\r\n\t\r\n\tpublic Row get(int index) {\r\n\t\treturn table.get(index);\r\n\t}\r\n\t\r\n\tpublic void add(Row row) {\r\n\t\ttable.addLast(row);\r\n\t}\r\n\t\r\n\tpublic int getLength() {\r\n\t\treturn table.size();\r\n\t}\r\n\t\r\n\t@Override\r\n\tpublic Iterator iterator() {\r\n\t\treturn new RowIterator(this);\r\n\t}\r\n}\r\n<\/pre>\n<p>Iterator\ub97c \uad6c\ud604\ud558\ub294 RowIterator \ud074\ub798\uc2a4\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\npackage pattern;\r\n\r\npublic class RowIterator implements Iterator {\r\n\tprivate Table table;\r\n\tprivate int index;\r\n\t\r\n\tpublic RowIterator(Table table) {\r\n\t\tthis.table = table;\r\n\t\tthis.index = -1;\r\n\t}\r\n\t\r\n\t@Override\r\n\tpublic boolean next() {\r\n\t\tindex++;\r\n\t\treturn index < table.getLength();\r\n\t}\r\n\r\n\t@Override\r\n\tpublic Object current() {\r\n\t\treturn table.get(index);\r\n\t}\r\n}\r\n<\/pre>\n<p>\uc800\uc7a5\uc18c\ub97c \uad6c\uc131\ud558\ub294 \uc2e4\uc81c \ub370\uc774\ud130\uc5d0 \ub300\ud55c Row \ud074\ub798\uc2a4\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\npackage pattern;\r\n\r\npublic class Row {\r\n\tprivate String name;\r\n\tprivate int age;\r\n\t\r\n\tpublic Row(String name, int age) {\r\n\t\tthis.name = name;\r\n\t\tthis.age = age;\r\n\t}\r\n\t\r\n\tpublic String getName() {\r\n\t\treturn name;\r\n\t}\r\n\t\r\n\tpublic int getAge() {\r\n\t\treturn age;\r\n\t}\r\n\t\r\n\tpublic String toString() {\r\n\t\treturn \"(\" + name + \", \" + age + \")\";\r\n\t}\r\n}\r\n<\/pre>\n<p>\uc2e4\ud589 \uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<pre class='code'>\r\n(Jane, 27)\r\n(Suji, 35)\r\n(Tom, 19)\r\n(Robin, 43)\r\n(Robert, 58)\r\n<\/pre>\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 Iterator \ud544\uc694\ud55c \uc0c1\ud669 \ubc30\uc5f4\uacfc \uac19\uc774 \ub3d9\uc77c\ud55c \ud615\ud0dc\uc758 \ub370\uc774\ud130\ub97c \uc5ec\ub7ec \uac1c \uc800\uc7a5\ud558\uace0 \uc788\ub294 \uc800\uc7a5\uc18c(Aggregator)\uac00 \uc788\ub2e4. \uc774 \uc800\uc7a5\uc18c\uc5d0 \uc800\uc7a5\ub41c \ub370\uc774\ud130\ub97c \uc21c\uc11c\ub300\ub85c \uc811\uadfc\ud558\uae30 \uc704\ud55c \ud328\ud134\uc774\ub2e4. \uc21c\uc11c\ub300\ub85c \uc811\uadfc\ud558\uae30 \uc704\ud55c \ubc29\ubc95\uc740 \uc800\uc7a5\uc18c\uc758 \uc885\ub958\uc640\ub294 \uc0c1\uad00\uc5c6\uc774 \ub3d9\uc77c\ud55c \ubc29\uc2dd(API)\uc744 \uc81c\uacf5\ud55c\ub2e4. \uc608\uc81c \ucf54\ub4dc Aggregator\uc640 Iterator \uc778\ud130\ud398\uc774\uc2a4\ub294 \uc800\uc7a5\uc18c\uc758 \ud615\ud0dc\uc640 \uc885\ub958\uc5d0 \uc0c1\uad00\uc5c6\uc774 \uc800\uc7a5\uc18c\ub97c \uad6c\uc131\ud558\ub294 \ub370\uc774\ud130\ub97c \uc21c\ucc28\uc801\uc73c\ub85c \ubaa8\ub450 \uc811\uadfc\ud558\uae30 \uc704\ud55c API\ub97c \uc81c\uacf5\ud55c\ub2e4. \uc774 \uc778\ud130\ud398\uc774\uc2a4\ub97c \uad6c\uc131\ud558\ub294 Table\uacfc &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=10362\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;[GoF] Iterator \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-10362","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\/10362","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=10362"}],"version-history":[{"count":14,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/10362\/revisions"}],"predecessor-version":[{"id":10574,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/10362\/revisions\/10574"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10362"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}