{"id":1137,"date":"2021-02-11T16:43:38","date_gmt":"2021-02-11T08:43:38","guid":{"rendered":"https:\/\/badgameshow.com\/fly\/?p=1137"},"modified":"2021-02-11T16:45:22","modified_gmt":"2021-02-11T08:45:22","slug":"%e5%89%b5%e5%bb%ba%e5%9e%8b%e6%a8%a1%e5%bc%8f-abstract-factory%e6%8a%bd%e8%b1%a1%e5%b7%a5%e5%bb%a0%e6%a8%a1%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/fly\/%e5%89%b5%e5%bb%ba%e5%9e%8b%e6%a8%a1%e5%bc%8f-abstract-factory%e6%8a%bd%e8%b1%a1%e5%b7%a5%e5%bb%a0%e6%a8%a1%e5%bc%8f\/","title":{"rendered":"\u5275\u5efa\u578b\u6a21\u5f0f-Abstract Factory(\u62bd\u8c61\u5de5\u5ee0\u6a21\u5f0f)"},"content":{"rendered":"<h1>Abstract Factory(\u62bd\u8c61\u5de5\u5ee0\u6a21\u5f0f)<\/h1>\n<ul>\n<li>\u6587\u7ae0\u76ee\u9304<br \/>\n<\/p>\n<ul>\n<li><a href=\"https:\/\/badgameshow.com\/fly\/\u5275\u5efa\u578b\u6a21\u5f0f-abstract-factory\u62bd\u8c61\u5de5\u5ee0\u6a21\u5f0f\/fly\/design-pattern\/#a\">\u4ecb\u7d39<\/a><br \/>\n<\/li>\n<li><a href=\"https:\/\/badgameshow.com\/fly\/\u5275\u5efa\u578b\u6a21\u5f0f-abstract-factory\u62bd\u8c61\u5de5\u5ee0\u6a21\u5f0f\/fly\/design-pattern\/#b\">\u597d\u8655<\/a><br \/>\n<\/li>\n<li><a href=\"https:\/\/badgameshow.com\/fly\/\u5275\u5efa\u578b\u6a21\u5f0f-abstract-factory\u62bd\u8c61\u5de5\u5ee0\u6a21\u5f0f\/fly\/design-pattern\/#c\">\u7a0b\u5f0f\u7bc4\u4f8b<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2><\/h2>\n<p><a id=\"a\"><\/a><\/p>\n<h3>\u4ecb\u7d39<\/h3>\n<h5>\u7576\u9019\u4e9b\u5c0f\u5de5\u5ee0\u51fa\u73fe\u4e00\u4e9b\u7522\u54c1\u4e0a\u7684\u4e0d\u540c\u5c31\u9700\u8981\u6709\u628a\u76f8\u95dc\u65b9\u6cd5\u62bd\u53d6\u51fa\u4f86<\/h5>\n<h5>EX:<\/h5>\n<h5>\u9999\u8549\u5de5\u5ee0 > \u9999\u8549\u3001\u9999\u8549\u5305\u88dd<\/h5>\n<h5>\u860b\u679c\u5de5\u5ee0 > \u860b\u679c\u3001\u860b\u679c\u5305\u88dd<\/h5>\n<h5>\u6a58\u5b50\u5de5\u5ee0 > \u6a58\u5b50\u3001\u6a58\u5b50\u5305\u88dd<\/h5>\n<p><\/p>\n<h5>\u6c34\u904b\u5de5\u5ee0 > \u8239\u3001\u8239\u9ad4\u5927\u5c0f<\/h5>\n<h5>\u9678\u904b\u5de5\u5ee0 > \u8eca\u3001\u8eca\u9ad4\u5927\u5c0f<\/h5>\n<h5>\u7a7a\u904b\u5de5\u5ee0 > \u98db\u6a5f\u3001\u98db\u6a5f\u5927\u5c0f<\/h5>\n<p><a id=\"b\"><\/a><\/p>\n<h3>\u597d\u8655<\/h3>\n<h5>\u63d0\u4f9b\u4e86\u4e00\u500b\u62bd\u8c61\u5c0d\u8c61\u53ef\u5275\u5efa\u6bcf\u7a2e\u4e0d\u540c\u7684\u7cfb\u5217,\u53ea\u8981\u900f\u904e\u62bd\u8c61\u5c0d\u8c61\u5275\u5efa,\u5c31\u4e0d\u6703\u7522\u751f\u4e0d\u4e00\u81f4\u7684\u7522\u54c1<\/h5>\n<p><a id=\"c\"><\/a><\/p>\n<h3>\u7a0b\u5f0f\u7bc4\u4f8b<\/h3>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/github.com\/MuHongWeiWei\/DesignPattern\/tree\/master\/src\/main\/abstractFactoryPattern\" title=\"Abstract Factory Pattern\" target=\"_blank\" rel=\"noopener\">Abstract Factory Pattern<\/a><\/p>\n<h6>\u5275\u5efa\u62bd\u8c61\u5de5\u5ee0\u985e<\/h6>\n<pre><code class=\"language-Kotlin line-numbers\">abstract class AbstractFactory {\n    abstract fun getFruit(): Fruit\n    abstract fun getBag(): Bag\n}\n<\/code><\/pre>\n<h6>\u5275\u5efa\u6c34\u679c\u7522\u54c1\u63a5\u53e3<\/h6>\n<pre><code class=\"language-Kotlin line-numbers\">interface Fruit {\n    fun eat()\n}\n<\/code><\/pre>\n<h6>\u5275\u5efa\u5305\u88dd\u7522\u54c1\u63a5\u53e3<\/h6>\n<pre><code class=\"language-Kotlin line-numbers\">interface Bag {\n    fun pack(fruit: Fruit)\n}\n<\/code><\/pre>\n<h6>\u5be6\u73fe\u9999\u8549\u7522\u54c1<\/h6>\n<pre><code class=\"language-Kotlin line-numbers\">class Banana : Fruit {\n    override fun eat() {\n        print(\"\u5403\u9999\u8549\\t\")\n    }\n}\n<\/code><\/pre>\n<h6>\u5be6\u73fe\u860b\u679c\u7522\u54c1<\/h6>\n<pre><code class=\"language-Kotlin line-numbers\">class Apple : Fruit {\n    override fun eat() {\n        print(\"\u5403\u860b\u679c\\t\")\n    }\n}\n<\/code><\/pre>\n<h6>\u5be6\u73fe\u6a58\u5b50\u7522\u54c1<\/h6>\n<pre><code class=\"language-Kotlin line-numbers\">class Orange : Fruit {\n    override fun eat() {\n        print(\"\u5403\u6a58\u5b50\\t\")\n    }\n}\n<\/code><\/pre>\n<h6>\u5be6\u73fe\u9999\u8549\u5305\u88dd\u7522\u54c1<\/h6>\n<pre><code class=\"language-Kotlin line-numbers\">class BananaBag : Bag {\n    override fun pack(fruit: Fruit) {\n        println(\"\u88dd\u9999\u8549\")\n    }\n}\n<\/code><\/pre>\n<h6>\u5be6\u73fe\u860b\u679c\u5305\u88dd\u7522\u54c1<\/h6>\n<pre><code class=\"language-Kotlin line-numbers\">class AppleBag : Bag {\n    override fun pack(fruit: Fruit) {\n        println(\"\u88dd\u860b\u679c\")\n    }\n}\n<\/code><\/pre>\n<h6>\u5be6\u73fe\u6a58\u5b50\u5305\u88dd\u7522\u54c1<\/h6>\n<pre><code class=\"language-Kotlin line-numbers\">class OrangeBag : Bag {\n    override fun pack(fruit: Fruit) {\n        println(\"\u88dd\u6a58\u5b50\")\n    }\n}\n<\/code><\/pre>\n<h6>\u5be6\u73fe\u9999\u8549\u5de5\u5ee0(\u53d6\u5f97\u9999\u8549,\u53d6\u5f97\u9999\u8549\u5305\u88dd)<\/h6>\n<pre><code class=\"language-Kotlin line-numbers\">class BananaFactory : AbstractFactory() {\n    override fun getFruit(): Fruit {\n        return Banana()\n    }\n\n    override fun getBag(): Bag {\n        return BananaBag()\n    }\n}\n<\/code><\/pre>\n<h6>\u5be6\u73fe\u860b\u679c\u5de5\u5ee0(\u53d6\u5f97\u860b\u679c,\u53d6\u5f97\u860b\u679c\u5305\u88dd)<\/h6>\n<pre><code class=\"language-Kotlin line-numbers\">class AppleFactory : AbstractFactory() {\n    override fun getFruit(): Fruit {\n        return Apple()\n    }\n\n    override fun getBag(): Bag {\n        return AppleBag()\n    }\n}\n<\/code><\/pre>\n<h6>\u5be6\u73fe\u6a58\u5b50\u5de5\u5ee0(\u53d6\u5f97\u6a58\u5b50,\u53d6\u5f97\u6a58\u5b50\u5305\u88dd)<\/h6>\n<pre><code class=\"language-Kotlin line-numbers\">class OrangeFactory : AbstractFactory() {\n    override fun getFruit(): Fruit {\n        return Orange()\n    }\n\n    override fun getBag(): Bag {\n        return OrangeBag()\n    }\n}\n<\/code><\/pre>\n<h3>\u57f7\u884c<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">fun main() {\n    AbstractFactoryTest().flyGetBanana()\n    AbstractFactoryTest().flyGetApple()\n    AbstractFactoryTest().flyGetOrange()\n}\n\nclass AbstractFactoryTest {\n\n    private lateinit var fruitFactory: AbstractFactory\n\n    fun flyGetBanana() {\n        fruitFactory = BananaFactory()\n        val banana = fruitFactory.getFruit()\n        banana.eat()\n        fruitFactory.getBag().pack(banana)\n    }\n\n    fun flyGetApple() {\n        fruitFactory = AppleFactory()\n        val apple = fruitFactory.getFruit()\n        apple.eat()\n        fruitFactory.getBag().pack(apple)\n    }\n\n    fun flyGetOrange() {\n        fruitFactory = OrangeFactory()\n        val orange = fruitFactory.getFruit()\n        orange.eat()\n        fruitFactory.getBag().pack(orange)\n    }\n}\n<\/code><\/pre>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2021\/02\/1-1.png\"><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2021\/02\/1-1.png\" alt=\"\" \/><\/a><\/p>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Abstract Factory(\u62bd\u8c61\u5de5\u5ee0\u6a21\u5f0f) \u6587\u7ae0\u76ee\u9304 \u4ecb\u7d39 \u597d\u8655 \u7a0b\u5f0f\u7bc4\u4f8b \u4ecb\u7d39 \u7576\u9019\u4e9b\u5c0f\u5de5\u5ee0\u51fa\u73fe\u4e00\u4e9b\u7522 &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":[173,51,15],"class_list":["post-1137","post","type-post","status-publish","format-standard","hentry","category-design-pattern","tag-abstract-factory","tag-design-pattern","tag-kotlin"],"_links":{"self":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/1137","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=1137"}],"version-history":[{"count":2,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/1137\/revisions"}],"predecessor-version":[{"id":1142,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/1137\/revisions\/1142"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/media?parent=1137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/categories?post=1137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/tags?post=1137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}