{"id":320,"date":"2021-09-11T04:56:27","date_gmt":"2021-09-11T04:56:27","guid":{"rendered":"https:\/\/boochlin.com\/?p=320"},"modified":"2025-05-22T04:32:32","modified_gmt":"2025-05-22T04:32:32","slug":"funny-vote-app-mvp-%e6%9b%b4%e6%96%b0%e9%9b%9c%e8%a8%98","status":"publish","type":"post","link":"https:\/\/boochlin.com\/?p=320","title":{"rendered":"Funny vote APP -MVP \u66f4\u65b0\u96dc\u8a18"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/boochlin.com\/wp-content\/uploads\/2017\/04\/g294.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-290\" src=\"https:\/\/boochlin.com\/wp-content\/uploads\/2017\/04\/g294.png\" alt=\"g294\" width=\"500\" height=\"250\" \/><\/a><a href=\"https:\/\/boochlin.com\/wp-content\/uploads\/2018\/09\/mvp.png\"><img decoding=\"async\" class=\"alignnone wp-image-335\" src=\"https:\/\/boochlin.com\/wp-content\/uploads\/2018\/09\/mvp.png\" alt=\"mvp\" width=\"500\" height=\"438\" \/><\/a><\/p>\n<p>\u597d\u4e00\u9663\u5b50\u5fd8\u8a18\u8981\u66f4\u65b0\u4e00\u4e0b blog\uff0c\u6c92\u60f3\u5230\u597d\u4e0d\u5bb9\u6613\u5efa\u7acb\u7684\u958b\u767c\u7fd2\u6163\u4e5f\u6703\u5fd8\u8a18\uff0c\u53ef\u898b\u6020\u60f0\u771f\u7684\u958b\u767c\u7684\u6e90\u982d\u554a(?)\uff0c\u79c9\u6301\u8005 something record \u7684\u7cbe\u795e\uff0c\u7e7c\u7e8c\u4fdd\u6301\u597d\u7fd2\u6163\u3002\u5176\u5be6\u9019\u4e00\u7bc7\u662f Funny vote \u958b\u767c\u672d\u8a18\u7684\u5f8c\u7e8c\uff0c\u4e3b\u8981\u662f\u8a18\u9304\u91cb\u51fa\u5f8c\u7684\u5e7e\u6b21\u6280\u8853\u6539\u7248\u7df4\u7fd2\u3002\u9806\u9053\u4e00\u984c\u4e0d\u6703\u6559\u4f60\u600e\u9ebc\u6539\uff0c\u600e\u9ebc\u7528\uff0c\u4e5f\u6c92\u653e\u4e0a\u5565\u7a0b\u5f0f\u78bc\uff0c\u5e7e\u4e4e\u90fd\u662f\u6211\u7684 murmur\u3002<\/p>\n<p>\u6839\u64da google \u5b98\u65b9\u7684 Android arch \u7684\u6280\u8853\u85cd\u5716\uff0c\u5c07 Funny vote \u5206\u6210\u5e7e\u500b branch \uff0c\u5404\u81ea\u653e\u4e0a\u60f3\u73a9\u73a9\u7684\u6280\u8853\u67b6\u69cb\uff0c\u4e3b\u8981\u53ef\u5206\u70ba<\/p>\n<ol>\n<li><a href=\"https:\/\/github.com\/boochlin06\/FunnyVote\/tree\/mvp\">MVP \u67b6\u69cb\u6539\u7248\uff0c\u88dc\u4e0a Unit test by mockito ,\u00a0instrument test by espresso , JaCoCo \u6574\u5165 travis\u3002<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/boochlin06\/FunnyVote\/tree\/mvp_dagger\">MVP_dagger \u5728 MVP \u67b6\u69cb\u4e0a\u4f7f\u7528 Dagger \u9032\u884c\u4f9d\u8cf4\u6ce8\u5165\u3002<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/boochlin06\/FunnyVote\/tree\/mvp_kotlin\">MVP_Kotlin \u5728 MVP \u67b6\u69cb\u4e0a\u6539\u7528 Kotlin \u91cd\u5beb\u3002<\/a><\/li>\n<\/ol>\n<p><!--more--><\/p>\n<h3>MVP \u67b6\u69cb\u6539\u7248<\/h3>\n<p>\u5148\u8aaa\u8aaa\u6700\u521d\u7684\u7a0b\u5f0f\u67b6\u69cb\u4e26\u6c92\u6709\u63a1\u7528 MVP \u67b6\u69cb\uff0c\u800c\u662f MVC \uff0c\u539f\u56e0\u6c92\u751a\u9ebc\u7279\u5225\u7684\uff0c\u5c31\u662f\u6211\u6c92\u60f3\u5230\u8981\u7528\u554a\uff0c\u4eba\u53ea\u8981\u4e00\u6025\u8005\u60f3\u51fa\u7522\u54c1\u6642\uff0c\u90fd\u53ea\u6703\u8003\u616e\u6700\u5feb\u505a\u51fa\u4f86\u7684\u65b9\u6cd5(\u4e5f\u4e0d\u6703\u60f3\u8981\u5beb test case)\uff0c\u9019\u4e26\u975e\u662f\u8aaa MVC \u662f\u500b\u7cdf\u7cd5\u4f46\u5feb\u901f\u7684\u67b6\u69cb(\u662f\u8aaa\u5230\u73fe\u5728 MVC \u5230\u5e95\u662f\u5565\uff0c\u597d\u50cf\u4e5f\u4e0d\u662f\u5f88\u78ba\u5b9a)\uff0c\u800c\u662f\u56e0\u70ba\u516c\u53f8\u7684\u6240\u6709project \u5e7e\u4e4e\u90fd\u662f MVC\u7684\u95dc\u4fc2\uff0c\u6240\u4ee5\u6700\u719f\u6089\uff0c\u53ef\u4ee5\u958b\u767c\u7684\u5f88\u5feb\uff0c\u4f46\u662f\u4e5f\u6df1\u6df1\u77e5\u9053\u4ed6\u7684\u7f3a\u9ede\u53ca\u512a\u9ede\uff0c\u4e14\u8ddf MVP \u6bd4\u8f03\u4e4b\u5f8c\uff0c\u591a\u591a\u5c11\u5c11\u80fd\u7406\u89e3 google \u60f3\u529b\u63a8 MVP \u67b6\u69cb\u7684\u539f\u56e0(\u5176\u4ed6\u9084\u6709\u4e00\u5806\u5566\uff0c\u50cf\u662f MVVM , Live Cycle , Clean arch)\u3002<\/p>\n<p>MVC \u6700\u4e3b\u8981\u7684\u554f\u984c\u662f\u8b93 Activity \u53bb\u8ca0\u8cac\u6240\u6709\u7684 Controller \u908f\u8f2f\u4efb\u52d9\uff0c\u4f46\u662f\u672c\u8eab\u53c8\u8ca0\u64d4 View \u5c55\u793a\uff0c\u7528\u6236\u4ecb\u9762\u64cd\u4f5c\u4ea4\u4e92\uff0c\u9019\u6a23\u8b8a\u6210 Controller \u548c View \u7684\u4efb\u52d9\u6df7\u96dc\u518d\u4e00\u8d77\uff0c\u6240\u4ee5\u5e38\u5e38\u6703\u770b\u5f97\u5230\u8d85\u904e 2000 \u884c\u7684 Activity \uff0c\u9019\u975e\u5e38\u81c3\u816b\uff0c\u6839\u64da clean code \u7684\u6982\u5ff5\uff0c\u9019\u80af\u5b9a\u6703\u9020\u6210 debug \u4e0a\u7684\u56f0\u96e3\uff0c\u56e0\u6b64 google \u63d0\u51fa\u4e86\u5207\u5206\u66f4\u4e7e\u6de8 MVP \u67b6\u69cb\u3002<\/p>\n<h4>VIEW \u53ea\u8ca0\u8cac UI Init , User \u64cd\u4f5c\u4e92\u52d5\uff0c\u4e0d\u80fd\u76f4\u63a5\u8207 Model \u6e9d\u901a\uff0c\u53ea\u80fd\u63a5\u53d7 Presenter \u7684\u6307\u4ee4\u3002<\/h4>\n<h4>Model \u53ea\u8ca0\u8cac\u8655\u7406\u8cc7\u6599\u5eab\u4e92\u52d5\uff0c\u63d0\u4f9b\u8cc7\u6599\u7d66 Presenter \u505a\u6c7a\u7b56\u3002<\/h4>\n<h4>Presenter \u5247\u8ca0\u8cac View \u8207 Model \u7684\u4e2d\u4ecb\u4e92\u52d5\uff0c\u8ca0\u8cac\u6240\u6709\u696d\u52d9\u908f\u8f2f\u3002<\/h4>\n<p>&nbsp;<\/p>\n<p>\u8ddf MVC \u5be6\u4f5c\u4e0a\u7684\u6700\u5927\u5dee\u7570\u5247\u662f\u8b93 Activity \u53ea\u55ae\u7d14\u5730\u53bb\u8655\u7406 View \u4efb\u52d9\uff0c\u628a\u539f\u672c\u5728 Activity \u4e2d\u7684 Controller \u7684\u908f\u8f2f\u4efb\u52d9\u5168\u90e8\u53e6\u5916\u62bd\u51fa\u653e\u5230 Presenter \u88e1\uff0c\u6240\u6709\u7684\u4ea4\u4e92\u4efb\u52d9\u5247\u900f\u904e View interface \u548c Presenter interface \u4f86\u9032\u884c\uff0c\u9019\u975e\u5e38\u65b9\u4fbf\u65bc Unit test\u3002\u5be6\u969b\u7a0b\u5f0f\u78bc\u5982\u4e0b<\/p>\n<p><a href=\"https:\/\/github.com\/boochlin06\/FunnyVote\/tree\/mvp\">Funny Vote MVP version Github<\/a><\/p>\n<p>\u5728\u6539\u7248\u6210 MVP \u67b6\u69cb\u7684\u540c\u6642\u4e5f\u88dc\u4e0a UT \uff0c\u6b63\u56e0\u70ba\u6709\u52a0\u5165\u6e2c\u8a66\u7684\u6982\u5ff5\uff0c\u66f4\u80fd\u7406\u89e3 MVP \u67b6\u69cb\u7684\u89e3\u5076\u512a\u9ede\u3002\u70ba\u4e86\u65b9\u4fbf\u6e2c\u8a66\u8003\u91cf\uff0c\u5728 Model , Presenter ,View \u4ea4\u4e92\u7684 interface \u8a2d\u8a08\u6642\uff0c\u81ea\u7136\u800c\u7136\u7684\u6703\u4f7f\u5f97 code \u8b8a\u5f97\u66f4\u4e7e\u6de8\uff0c\u6211\u60f3\u9019\u61c9\u8a72\u5c31\u662f TDD \u7684\u7406\u5ff5\u3002\u96d6\u7136\u6211\u4e26\u6c92\u6709\u8b93 converge rate \u885d\u9ad8\uff0c\u4e0d\u904e\u4e3b\u8981\u662f\u56e0\u70ba\u81ea\u5df1\u61f6\u5f97\u5565\u90fd\u52a0\u4e0a\u6e2c\u8a66\uff0c\u53ea\u4e3b\u8981\u6e2c\u8a66\u6838\u5fc3\u908f\u8f2f\u696d\u52d9\u3002<\/p>\n<p>\u5be6\u4f5c\u958b\u767c\u5fc3\u5f97<\/p>\n<ul>\n<li>\u901a\u5e38\u4e00\u500b VIEW\uff0c\u5c0d\u61c9\u4e00\u500b Presenter\uff0c\u4f46\u662f\u5982\u679c\u4e00\u500b activity \u6709\u5169\u500b fragment view \u4e14\u81ea\u5df1\u90e8\u5206 activity view\uff0c\u50cf\u662f Funny vote \u5275\u5efa\u6295\u7968\u9801\u9762\uff0c\u5148\u4e0d\u8aaa\u6211\u7576\u521d UI \u8a2d\u8a08\u662f\u600e\u9ebc\u60f3\u7684\uff0c\u6700\u521d\u7684\u601d\u8def\u8a8d\u70ba\u61c9\u8a72\u8b93\u4e00\u500b CreateVotePresenter \u53bb Handle setting fragment view and option fragment view \u548c activity \u7684 title and image view\u3002<\/li>\n<\/ul>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/boochlin.com\/wp-content\/uploads\/2017\/04\/Screenshot_20170411-000636.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-299\" src=\"https:\/\/boochlin.com\/wp-content\/uploads\/2017\/04\/Screenshot_20170411-000636.png\" alt=\"Screenshot_20170411-000636\" width=\"300\" height=\"600\" \/><\/a><\/p>\n<p style=\"padding-left: 60px;\">\u6703\u9019\u6a23\u60f3\uff0c\u53ea\u662f\u55ae\u7d14\u7684\u8a8d\u70ba activity\u00a0 \u8ddf fragment\u00a0 View \u4e4b\u9593\u7684\u4e92\u52d5\uff0c\u53ef\u4ee5\u5f88\u7c21\u55ae\u7684\u5728\u4e00\u500b presenter \u4e2d\u63a7\u5236\uff0c\u53ef\u4ee5\u5c11\u6389\u5f88\u591a\u696d\u52d9\u4e0a\u7684 callback \uff0c\u53ef\u4ee5\u8b93 code \u8b8a\u5f97\u6613\u8b80\u3002\u4f46\u662f\u4e8b\u60c5\u679c\u7136\u4e0d\u662f\u5c0f\u5f1f\u60f3\u7684\u90a3\u9ebc\u7c21\u55ae\uff0c\u5728\u7d93\u904e\u5be6\u4f5c\u5f8c\uff0c\u767c\u73fe\u5c31\u6703\u767c\u751f\u4e00\u500b presenter \u7684 code \u592a\u591a\uff0c\u4e14\u592a\u591a view \u8981\u4e00\u8d77 ready \uff0c \u9019\u5728\u4e00\u500b\u4eba\u958b\u767c\u6642\u9084\u597d\uff0c\u4f46\u5982\u679c\u662f\u591a\u4eba\u958b\u767c\u6642\uff0c\u5c0d\u65bc\u5354\u8abf interface\u8a2d\u8a08\u5de5\u4f5c \u5c31\u6703\u6709\u6975\u5927\u7684\u8ca0\u64d4\u3002<\/p>\n<p style=\"padding-left: 60px;\">\u7576\u7136\u9019\u4e26\u975e\u662f\u7d55\u5c0d\u7684\u539f\u5247\uff0c\u4e3b\u8981\u770b widget \u7684\u5167\u5bb9\u91cf\u4f86\u5b9a\u7fa9 MVP \u6703\u6bd4\u8f03\u597d\uff0c\u81f3\u65bc Callback \u592a\u591a\u9019\u500b\u554f\u984c\uff0c\u7576\u7136\u4e0d\u662f\u53ea\u6709\u6211\u60f3\u5230\uff0c\u5404\u65b9\u5927\u795e\u65e9\u5df2\u6709\u89e3\u6cd5\uff0c\u4e5f\u5c31\u662f RxJava \uff0c\u8a72\u6709\u7684 callback \u662f\u5c11\u4e0d\u4e86\uff0c\u4f46\u662f\u53ef\u4ee5\u8b93 callback \u597d\u5275\u9020\uff0c\u597d\u7ba1\u7406\uff0c\u9019\u5c31\u662f\u597d\u6846\u67b6\u3002<\/p>\n<ul>\n<li>Presenter \u4e0d\u61c9\u8a72\u6709\u4efb\u4f55\u76f8\u95dc android \u7684 object and method\uff0c\u9019\u6c92\u5565\u597d\u8cea\u7591\u7684\uff0c\u53ea\u662f\u6211\u60f3\u4f86\u81ea\u6211\u63d0\u9192\u800c\u5df2\uff0c\u4e0d\u7136\u4ee5\u5f8c\u5beb UT \u53ea\u6703\u60f3\u54ed\u3002Presenter \u4e5f\u4e0d\u61c9\u8a72\u50b3\u5165 Adapter \u88e1\u3002<\/li>\n<li>Model \u8a2d\u8a08\u4e0a\uff0c\u5982\u679c\u5e38\u5e38\u6703\u9047\u5230\u5f8c\u7aef\u9084\u672a ready \u6642\uff0c\u5e38\u5e38\u9700\u8981\u81ea\u5df1\u5148\u5728 local fake data\uff0c\u7576\u5f8c\u7aef\u5b8c\u6210\u5f8c\u5728\u91cd\u65b0\u63a5\u4e0a\uff0c\u9019\u7a2e\u60c5\u6cc1\u4e0b\u975e\u5e38\u9069\u5408\u4f7f\u7528\u6a23\u677f\u6a21\u5f0f\uff0c\u642d\u914d\u4e0a Injection \u548c build variant \u53ef\u4ee5\u7c21\u55ae\u5340\u5206\u51fa\u4f55\u6642\u7528\u4f55\u7a2e content \uff0c\u8d85\u7d1a\u8212\u723d\u3002\u5728\u9019\u500b\u6982\u5ff5\u4e4b\u4e0a\uff0c\u540c\u6642\u65b9\u4fbf\u6e2c\u8a66\u7684\u76ee\u7684\uff0cDagger \u7684\u4f9d\u8cf4\u6ce8\u5165\u6846\u67b6\u4e5f\u56e0\u6b64\u88ab\u63d0\u51fa\u4f86\u3002<\/li>\n<li>\u6e2c\u8a66\u6846\u67b6\u5728\u6c92\u6709\u7279\u6b8a\u9700\u6c42\u4e0b\uff0c\u5247\u4f9d\u64da <a href=\"https:\/\/developer.android.com\/training\/testing\/\">google \u5efa\u8b70<\/a>\u7684 mockito \u505a UT, Espresso \u505a instrument test\uff0c\u76ee\u524d\u611f\u89ba\u5c31\u662f\u5beb\u800c\u5df2\uff0c\u4e5f\u6c92\u7528\u904e\u5225\u7684\u6e2c\u8a66\u6846\u67b6\uff0c\u786c\u8981\u8aaa\u7684\u8a71\u5c31\u662f test method \u7684\u547d\u540d\u600e\u9ebc\u6a23\u6bd4\u8f03\u597d (<a href=\"http:\/\/teddy-chen-tw.blogspot.com\/2016\/05\/blog-post_12.html\">\u5927\u5e2b\u8aaa\u6cd5<\/a>)\uff0c\u4e00\u53ea\u4ee5\u4f86\u90fd\u662fPresenter,View UT \u7528\u4ee5\u60f3\u6e2c\u5565\u529f\u80fd\u4f5c\u70ba\u547d\u540d\u898f\u5247\uff0cModel UT\u5247\u591a\u63a1\u7528\u9810\u671f\u884c\u70ba\u52a0\u4e0a\u6e2c\u8a66\u72c0\u614b\u4f5c\u70ba\u547d\u540d\u898f\u5247\uff0c Instrument test \u5247\u4ee5\u00a0<span style=\"color: #000000;\">Given-When-Then \u70ba\u547d\u540d\u57fa\u6e96\u3002\u8001\u5be6\u8aaa\u9019\u6a23\u597d\u4e0d\u597d\u6211\u4e5f\u4e0d\u9069\u5f88\u6e05\u695a\uff0c\u500b\u4eba\u89ba\u5f97\u6709\u898f\u5247\u5c31\u597d\u3002<\/span><\/li>\n<li>CI \u9019\u500b\u4ee5\u524d\u5b8c\u5168\u6c92\u6709\u6478\u904e\uff0c\u4f46\u662f\u807d\u8aaa Travis \u8d85\u7c21\u55ae\uff0c\u6240\u4ee5\u6211\u5c31\u7d66\u4ed6\u84cb\u4e0b\u53bb\u4e86\uff0c\u8001\u5be6\u8aaa\u723d\u611f\u5341\u8db3\uff0c\u770b\u4ed6\u5728\u90a3\u908a\u81ea\u52d5\u5316\uff0c\u6211\u5728\u770b youtube \u771f\u7684\u65b9\u4fbf<\/li>\n<\/ul>\n<p style=\"padding-left: 60px;\">\u57fa\u672c\u529f\u80fd\u53ea\u9a57\u8b49\u80fd\u4e0d\u80fd build \u904e\uff0c\u5982\u679c\u6709\u5beb\u6e2c\u8a66\u7684\u8a71\uff0c\u5247\u6703\u9806\u624b\u8dd1\u5b8c\uff0c\u53ef\u662f\u537b\u767c\u73fe\u7528 Android studio \u90fd\u5167\u5efa\u986f\u793a coverage rate \u7bc4\u570d\uff0c\u7d50\u679c Travis \u6c92\u6709\u9806\u624b\u63d0\u4f9b\u9019\u529f\u80fd\u4e0d\u662f\u592a\u53ef\u60dc\u4e86\u55ce\uff0c\u56e0\u6b64\u4e5f\u6574\u5165 jacoco \uff0c\u6e2c\u8a66\u5b8c\u5f8c\u81ea\u52d5 gen report (<a href=\"https:\/\/github.com\/codecov\/example-android\">\u5927\u795e\u6574\u5408\u597d\u7684<\/a>)\u3002<\/p>\n<p style=\"padding-left: 30px;\">\u7bc0\u9304\u67e5\u8cc7\u6599\u6642\u770b\u5230\u7684\u540d\u8a00<\/p>\n<blockquote><p>You need to provide a way of accessing the member variables so you can pass in a mock (the most common ways would be a setter method or a constructor which takes a parameter).<\/p>\n<p>If your code doesn&#8217;t provide a way of doing this, it&#8217;s incorrectly factored for TDD (Test Driven Development).<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h3>MVP with Dagger<\/h3>\n<p>\u5728\u4e0a\u4e00\u7ae0\u7bc0\u8ac7\u5230\u5169\u500b\u53ef\u4ee5\u5728 MVP \u67b6\u69cb\u4e0a\u4f7f\u7528\u7684\u6846\u67b6\uff0c\u4e00\u500b\u662f\u89e3\u6c7a\u5927\u91cf Callback \u4ee5\u53ca\u6d41\u7a0b\u5316\u7684\u00a0 Rxjava \uff0c\u53e6\u4e00\u500b\u662f\u89e3\u6c7a\u5927\u91cf new \u4f9d\u8cf4\u4e14\u65b9\u4fbf Injection \u7ba1\u7406\u7684 Dagger2\uff0c\u800c\u9019\u500b\u7ae0\u7bc0\u5247\u662f\u8ac7\u5f15\u5165 Dagger2 \u7684\u5fc3\u5f97\uff0c\u4f60\u8aaa\u70ba\u4f55\u6c92\u6709\u4e00\u8d77\u5f15\u5165 Rxjava \uff0c\u96e3\u9053\u90a3\u4e9b\u554f\u984c\u4e0d\u7528\u4e00\u8d77\u89e3\u6c7a\u55ce\uff0c\u6211\u7d55\u5c0d\u4e0d\u6703\u8aaa\u56e0\u70ba\u770b\u8d77\u4f86\u592a\u7c21\u55ae\u4e86\uff0c\u6240\u4ee5\u6211\u61f6\u5f97\u7528\uff0c\u800c\u662f\u56e0\u70ba Kotlin \u5c31\u76f4\u63a5\u628a\u9019\u584a\u6574\u5408\u5f97\u66f4\u597d\uff0c\u96d6\u7136\u6211\u77e5\u9053\u9019\u6709\u9ede\u96de\u817f\u6bd4\u61f6\u89ba\u7684\u554f\u984c\uff0c\u4f46\u662f\u56e0\u70ba\u9019\u4e4b\u5f8c\u6211\u6253\u7b97\u76f4\u63a5\u5beb kotlin \u7248\u672c\uff0c\u6240\u4ee5\u5c31\u5ffd\u7565\u4e86\u3002<\/p>\n<p>\u6839\u64da\u4e0a\u9762\u4e00\u5806\u5c41\u8a71\uff0c\u76f4\u63a5\u958b\u59cb Dagger \u6574\u5408\uff0c\u901a\u5e38\u4e00\u958b\u59cb\u67e5\u627e\u8cc7\u6599\u90fd\u6703\u807d\u5230 MVP + Retrofit + RxJava +Dagger \u6574\u500b\u8d85\u8212\u723d\uff0c\u4f46\u662f\u63a5\u4e0b\u4f86\u5c31\u6703\u770b\u5230\u8aaa Dagger \u7684\u5b78\u7fd2\u96e3\u5ea6\u6bd4\u8f03\u9ad8\uff0c\u5927\u90e8\u5206\u7528\u5728\u5927\u578b\u5354\u4f5c\u5c08\u6848\u6bd4\u8f03\u9069\u5408\uff0c\u6069~\u8001\u5be6\u8aaa\u6211\u89ba\u5f97\u9084\u884c\u963f\uff0c\u4ee5\u524d\u6709\u73a9\u904e\uff0c\u539f\u672c\u9810\u4f30\u500b\u516b\u5c0f\u6642\u61c9\u8a72\u53ef\u4ee5\u641e\u5b9a\uff0c\u6700\u5f8c\u82b1\u4e8615\u5c0f\u6642\uff0c\u662f\u6bd4\u8f03\u9ebb\u7169\u5566\uff0c\u4e3b\u8981\u662f dagger \u7684\u932f\u8aa4\u984c\u793a\u8a0a\u606f\u6709\u9ede\u96e3\u61c2\u3002<\/p>\n<p>\u9019\u7a2e\u6771\u897f\u5c31\u662f\u521d\u59cb\u5316\u9ebb\u7169\uff0c\u4f46\u662f\u5f8c\u4f86\u7528\u8d77\u4f86\u6574\u500b\u8212\u723d\uff0c\u6700\u660e\u986f\u7684\u5c31\u662f MVP \u7248\u672c\u6642\u6709\u4e00\u500b Injection.java \uff0c\u9019\u6771\u897f\u53ef\u4ee5\u6839\u64da\u653e\u7684\u8cc7\u6599\u593e\u4ee5\u53ca build variant \u53bb\u63d0\u4f9b debug version , prod version \u4e0d\u4e00\u6a23\u7684\u5be6\u4f5c\u6ce8\u5165\uff0c\u4f46\u662f Dagger \u5c31\u4e0d\u7528\u4e86\u963f\uff0c\u7b49\u7b49\uff0c\u597d\u50cf\u53ea\u662f\u79fb\u5230 Module \u4e86\uff0c\u4e0d\u8981\u5c0f\u770b\u9019\u500b Module , Component \uff0c\u4e00\u5806\u5947\u5999\u7684 new \u5c31\u901a\u901a\u4e0d\u898b\u4e86(\u89e3\u5076\u7684\u6027\u8cea\u5c31\u51fa\u73fe\u4e86)\uff0c\u4e5f\u4e0d\u7528\u7ba1\u7406\u7269\u4ef6\u7684\u751f\u547d\u9031\u671f(\u5c08\u6ce8\u696d\u52d9\u908f\u8f2f)\uff0c\u5728\u7ba1\u7406\u4e0a\u4e5f\u56e0\u70ba\u6709\u597d\u597d\u7684\u5206\u985e\uff0c\u958b\u767c\u6548\u7387\u4e5f\u6703\u63d0\u9ad8(\u6e05\u6670\u7684 code)\uff0c\u64b0\u5beb UT \u4e5f\u6703\u65b9\u4fbf\u5f97\u591a\u3002\u5be6\u969b\u7a0b\u5f0f\u78bc\u5982\u4e0b<\/p>\n<p><a href=\"https:\/\/github.com\/boochlin06\/FunnyVote\/tree\/mvp_dagger\">Funny Vote MVP with Dagger2 version Github<\/a><\/p>\n<p>\u5be6\u4f5c\u958b\u767c\u5fc3\u5f97:<\/p>\n<ul>\n<li>\u4f7f\u7528\u4efb\u4f55\u65b0\u6846\u67b6\u958b\u767c\u90fd\u8acb\u5148\u7406\u89e3\u70ba\u4f55\u8981\u5c0e\u5165\uff0c\u4ee5 Dagger \u4f86\u8aaa\uff0c\u4e3b\u8981\u662f\u89e3\u6c7a\u4f9d\u8cf4\u56b4\u91cd\u7684\u554f\u984c\uff0c\u63a5\u8005\u5c31\u6703\u5f15\u5c0e\u5230\u65b9\u4fbf\u6e2c\u8a66\u7684\u597d\u8655\u3002\u4f46\u662f\u5c0e\u5165\u6846\u67b6\u90fd\u6703\u6709\u5b83\u61c9\u8a72\u4ed8\u51fa\u7684\u4ee3\u50f9\uff0c\u500b\u4eba\u89ba\u5f97\u6700\u7169\u7684\u662f\u521d\u59cb\u5316\u6d41\u7a0b\uff0c\u63a5\u8005\u70ba\u4e86\u8b93 Module , Component\u6574\u500b\u6d41\u7a0b\u80fd\u9054\u5230\u6ce8\u5165\u7684\u6548\u679c\uff0c\u5927\u6982\u6703\u591a\u51fa\u5169\u500d\u7684\u63a5\u53e3\u8a2d\u8a08\uff0c\u771f\u7684\u4e00\u822c\u5c0f\u578b\u958b\u767c\u7684 solo \u73a9\u5bb6\u5011\uff0c\u53ef\u4ee5\u597d\u597d\u601d\u8003\u9700\u8981\u55ce?<\/li>\n<li>\u7531\u65bc\u591a\u51fa\u5927\u91cf\u00a0\u00a0Module , Component \u7684\u7269\u4ef6\u548c\u63a5\u53e3\u8a2d\u8a08\uff0c\u9019\u5c31\u662f\u4e00\u500b\u9ebb\u7169\u7684\u554f\u984c\uff0c\u5beb\u7684\u7a0b\u5f0f\u78bc\u8d8a\u591a\u5c31\u8d8a\u6709\u6a5f\u6703\u51fa BUG\uff0c\u90a3\u9ebc\u554f\u984c\u4f86\u4e86\uff0c\u5c31\u8981\u601d\u8003\u6709\u6c92\u6709\u8fa6\u6cd5\u7c21\u5316\uff0c\u56e0\u70ba\u5927\u90e8\u5206\u7684 Module, Component\u00a0 \u96d6\u7136\u4e00\u5806\u63a5\u53e3\u8981\u8a2d\u8a08\uff0c\u4f46\u5927\u90fd\u662f\u6a21\u677f\u5316\u7684\u4ee3\u78bc\uff0c\u679c\u7136 google \u5927\u795e\u63d0\u51fa\u4e86<a href=\"https:\/\/google.github.io\/dagger\/android\">dagger.android<\/a>\u00a0\u7684\u5de5\u5177\uff0c\u7528 annotation \u53bb\u7701\u7565\u6a21\u677f\u4ee3\u78bc\uff0c\u8b93 compiler \u53bb\u81ea\u52d5\u751f\u6210\u7a0b\u5f0f\u78bc\u3002<\/li>\n<li>\u6a21\u7d44\u89e3\u5076\u5f8c\uff0c\u52d9\u5fc5\u5beb\u6e2c\u8a66\uff0c\u8212\u723d<\/li>\n<\/ul>\n<p>\u7bc0\u9304\u67e5\u8cc7\u6599\u6642\u770b\u5230\u7684\u540d\u8a00\uff0c\u5982\u679c\u5beb\u5b8c\u4f60\u6709\u9019\u6a23\u7684\u611f\u89ba\uff0c\u4ee3\u8868..GOOGLE \u5f88\u53b2\u5bb3\u554a<\/p>\n<blockquote><p>Dependency injection frameworks can simplify the code you write and provide an adaptive environment that&#8217;s useful for testing and other configuration changes.<\/p>\n<p>If you intend to use a dependency injection framework in your app, consider using\u00a0<a class=\"external-link\" href=\"http:\/\/google.github.io\/dagger\/\">Dagger 2<\/a>. Dagger does not use reflection to scan your app&#8217;s code. Dagger&#8217;s static, compile-time implementation means that it can be used in Android apps without needless runtime cost or memory usage.<\/p><\/blockquote>\n<p>\u4ee5\u4e0a\u662f\u672c\u6b21\u5c0f\u5f1f\u7684\u611f\u60f3\uff0c\u6211\u771f\u7684\u61f6\u5f97\u8cbc CODE \uff0c\u5404\u4f4d\u771f\u7684\u60f3\u770b\u53bb Github \u5427\uff0c\u901a\u901a\u90fd\u653e\u5728\u90a3\uff0c\u81f3\u65bc kotlin \u7248\u672c\u6211\u5247\u653e\u5230\u4e0b\u4e00\u7bc7\uff0c\u5c0d\u5c0f\u5f1f\u4f86\u8aaa kotlin \u7b97\u662f\u771f\u7684\u5b8c\u5168\u6c92\u7528\u904e\uff0c\u6240\u4ee5\u6e2c\u91cd\u9ede\u6703\u591a\u653e\u5728\u600e\u9ebc\u7528\uff0c\u6839\u672c\u7bc7\u6027\u8cea\u4e0d\u592a\u76f8\u540c\u3002\u6240\u4ee5\u65b0\u958b\u6587\u7ae0<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u597d\u4e00\u9663\u5b50\u5fd8\u8a18\u8981\u66f4\u65b0\u4e00\u4e0b blog\uff0c\u6c92\u60f3\u5230\u597d\u4e0d\u5bb9\u6613\u5efa\u7acb\u7684\u958b\u767c\u7fd2\u6163\u4e5f\u6703\u5fd8\u8a18\uff0c\u53ef\u898b\u6020\u60f0\u771f\u7684\u958b\u767c\u7684\u6e90\u982d\u554a(?)\uff0c\u79c9\u6301\u8005 something record \u7684\u7cbe\u795e\uff0c\u7e7c\u7e8c\u4fdd\u6301\u597d\u7fd2\u6163\u3002\u5176\u5be6\u9019\u4e00\u7bc7\u662f F&#8230;<\/p>\n","protected":false},"author":1,"featured_media":602,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[50,77,75,76],"tags":[],"_links":{"self":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/320"}],"collection":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=320"}],"version-history":[{"count":1,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/320\/revisions"}],"predecessor-version":[{"id":597,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/320\/revisions\/597"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/media\/602"}],"wp:attachment":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}