{"id":333,"date":"2020-04-02T15:48:35","date_gmt":"2020-04-02T07:48:35","guid":{"rendered":"https:\/\/badgameshow.com\/fly\/?p=333"},"modified":"2020-05-27T15:28:25","modified_gmt":"2020-05-27T07:28:25","slug":"design-pattern-bridge-pattern%e6%a9%8b%e6%8e%a5%e6%a8%a1%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/fly\/design-pattern-bridge-pattern%e6%a9%8b%e6%8e%a5%e6%a8%a1%e5%bc%8f\/","title":{"rendered":"Design Pattern Bridge Pattern(\u6a4b\u63a5\u6a21\u5f0f)"},"content":{"rendered":"<h1>Bridge Pattern(\u6a4b\u63a5\u6a21\u5f0f)<\/h1>\n<h4>\u628a\u62bd\u8c61\u985e\u8207\u5be6\u73fe\u985e\u89e3\u8026,\u8b93\u4e8c\u8005\u53ef\u4ee5\u7368\u7acb\u8b8a\u5316,\u9019\u7a2e\u6a21\u5f0f\u6703\u8b93\u4e00\u500binterface\u4f5c\u70ba\u6a4b\u63a5\u7684\u63a5\u53e3,\u8b93\u5be6\u9ad4\u985e\u7684\u529f\u80fd\u8207\u63a5\u53e3\u985e\u7684\u529f\u80fd\u80fd\u7368\u7acb\u5b8c\u6210\u4e14\u4e92\u4e0d\u5f71\u97ff<\/h4>\n<h2>\u597d\u8655<\/h2>\n<h4>\u53ef\u4ee5\u8b93\u62bd\u8c61\u985e\u548c\u5be6\u73fe\u985e\u5206\u96e2\u4e26\u4e14\u65b9\u4fbf\u672a\u4f86\u64f4\u5c55,\u4f86\u9054\u5230\u89e3\u8026\u7684\u6548\u679c<\/h4>\n<h2>\u7a0b\u5f0f\u7bc4\u4f8b<\/h2>\n<h3>\u5efa\u7acb Bridge \u7684\u8a2d\u8a08\u6a21\u5f0f\u6709\u5e7e\u500b\u8981\u6ce8\u610f\u7684\u5730\u65b9<\/h3>\n<h4>\u9019\u908a\u628a\u63a5\u53e3\u5148\u547d\u540d\u70baDrawAPI\u6bd4\u8f03\u597d\u7406\u89e3<\/h4>\n<h4>1.\u5148\u5275\u5efa\u4e00\u500bDrawAPI\u4f5c\u70ba\u62bd\u8c61\u985e\u8207\u5be6\u73fe\u985e\u7684\u63a5\u53e3<\/h4>\n<h4>2.\u628a\u5275\u5efa\u597d\u7684DrawAPI\u7576\u4f5c\u53c3\u6578\u50b3\u7d66\u62bd\u8c61\u985e,\u4e26\u5beb\u51fa\u62bd\u8c61\u65b9\u6cd5,\u9019\u6a23\u4e4b\u5f8c\u90fd\u53ef\u4ee5\u8abf\u7528\u65b9\u6cd5\u4f86\u540c\u6b65\u57f7\u884c<\/h4>\n<h4>3.\u5be6\u73fe\u62bd\u8c61\u985e\u4e26\u8907\u5beb\u62bd\u8c61\u65b9\u6cd5,\u4e4b\u5f8c\u8abf\u7528DrawAPI\u7684\u65b9\u6cd5\u628a\u53c3\u6578\u90fd\u53cd\u56de\u7d66DrawAPI,\u8b93\u4e4b\u5f8c\u8abf\u7528\u7684\u4eba\u4e0d\u7528\u6e05\u695a\u5167\u90e8\u69cb\u9020\u53ea\u8981\u7d66\u7279\u5b9a\u53c3\u6578\u5c31\u80fd\u5f97\u5230\u7269\u4ef6<\/h4>\n<h4>4.\u6240\u6709\u60f3\u8981\u8abf\u7528\u7684\u985e,\u90fd\u8981\u5be6\u73feDrawAPI\u88e1\u9762\u7684\u65b9\u6cd5<\/h4>\n<h3>\u6a4b\u63a5\u63a5\u53e3<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">interface DrawAPI {\n    fun drawCircle(x: Int, y: Int, radius: Int)\n    fun drawSquare(x: Int, y: Int)\n}\n<\/code><\/pre>\n<h3>\u62bd\u8c61\u985e<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">abstract class Shape(drawAPI: DrawAPI) {\n    abstract fun draw()\n}\n<\/code><\/pre>\n<h3>\u5be6\u73fe\u62bd\u8c61\u985e<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">class Square(val x: Int, val y: Int, val drawAPI: DrawAPI) : Shape(drawAPI) {\n    override fun draw() {\n        drawAPI.drawSquare(x,y)\n    }\n}\n<\/code><\/pre>\n<pre><code class=\"language-Kotlin line-numbers\">class Circle(val x: Int, val y: Int, val radius: Int, val drawAPI: DrawAPI) : Shape(drawAPI) {\n    override fun draw() {\n        drawAPI.drawCircle(x,y,radius)\n    }\n}\n<\/code><\/pre>\n<h3>\u4e00\u822c\u985e\u5225<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">class Yellow : DrawAPI {\n    override fun drawCircle(x: Int, y: Int, radius: Int) {\n        println(\"Draw Circle Yellow radius:<span class=\"katex math inline\">{radius}  x:<\/span>{x} y:<span class=\"katex math inline\">{y}\")\n    }\n\n    override fun drawSquare(x: Int, y: Int) {\n        println(\"Draw Square Yellow x:<\/span>{x} y:${y}\")\n    }\n}\n<\/code><\/pre>\n<h3>\u57f7\u884c\u7d50\u679c<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">fun main() {\n    val yellowSquare = Square(100,50, Yellow())\n    val yellowCircle = Circle(100,50, 50, Yellow())\n    yellowSquare.draw()\n    yellowCircle.draw()\n}\n\n\nDraw Square Yellow x:100 y:50\nDraw Circle Yellow radius:50  x:100 y:50\n<\/code><\/pre>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Bridge Pattern(\u6a4b\u63a5\u6a21\u5f0f) \u628a\u62bd\u8c61\u985e\u8207\u5be6\u73fe\u985e\u89e3\u8026,\u8b93\u4e8c\u8005\u53ef\u4ee5\u7368\u7acb\u8b8a\u5316,\u9019\u7a2e\u6a21\u5f0f\u6703\u8b93\u4e00\u500binter &hellip; <\/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,"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[50],"tags":[13,53,51],"class_list":["post-333","post","type-post","status-publish","format-standard","hentry","category-design-pattern","tag-android","tag-bridge-pattern","tag-design-pattern"],"_links":{"self":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/comments?post=333"}],"version-history":[{"count":5,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/333\/revisions"}],"predecessor-version":[{"id":536,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/333\/revisions\/536"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/media?parent=333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/categories?post=333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/tags?post=333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}