{"id":98,"date":"2025-01-15T06:24:00","date_gmt":"2025-01-15T06:24:00","guid":{"rendered":"https:\/\/boochlin.com\/?p=98"},"modified":"2025-05-21T21:55:08","modified_gmt":"2025-05-21T21:55:08","slug":"clean-code-%e7%84%a1%e6%9a%87%e7%9a%84%e7%a8%8b%e5%bc%8f%e7%a2%bc-%e6%9b%b8%e6%91%98%e5%bf%83%e5%be%97%ef%bc%88%e4%b8%80%ef%bc%89","status":"publish","type":"post","link":"https:\/\/boochlin.com\/?p=98","title":{"rendered":"Clean code: \u7121\u7455\u7684\u7a0b\u5f0f\u78bc &#8211; \u66f8\u6458\u5fc3\u5f97\uff08\u4e00\uff09"},"content":{"rendered":"<p><img fetchpriority=\"high\" decoding=\"async\" class=\"\" src=\"http:\/\/im1.book.com.tw\/image\/getImage?i=http:\/\/www.books.com.tw\/img\/001\/057\/98\/0010579897.jpg&amp;v=513f2000&amp;w=348&amp;h=348\" alt=\"\" width=\"411\" height=\"411\" \/><img decoding=\"async\" class=\"\" src=\"http:\/\/www.osnews.com\/images\/comics\/wtfm.jpg\" alt=\"wtf\" width=\"438\" height=\"413\" \/><\/p>\n<p>\u300e<span style=\"color: #ff0000;\">\u552f\u4e00\u6709\u6548\u7684\u7684\u300e\u7a0b\u5f0f\u54c1\u8cea\u300f\u5ea6\u91cf\u55ae\u4f4d\uff1a \u6bcf\u5206\u9418\u7f75\u9ad2\u8a71\u7684\u6b21\u6578(wtf\/minutes)<\/span>\u300f<a href=\"http:\/\/www.osnews.com\/story\/19266\/WTFs_m\">\u7248\u6b0a\u7db2\u5740\u9644\u4e0a<\/a><br \/>\n\u9019\u53e5\u8a71\u8b93\u6211\u60f3\u5230\u540c\u4e8b\u6539\u5176\u4ed6\u90e8\u9580\u7a0b\u5f0f\u78bc\u6642\u7684\u72c0\u6cc1\uff0c\u6211\u60f3\u4ee5\u6b64\u4f5c\u70ba\u5f15\u8a00\uff0c\u5df2\u7d93\u76f8\u7576\u8db3\u5920\u7684\u8868\u793a\u51fa \u5beb\u51faclean code \u7684\u91cd\u8981\u6027<br \/>\n\uff08\u5e8f\uff09<\/p>\n<p>\u8a8d\u771f\u4e00\u9ede\u7684\u8a71\u5c31\u662f\uff1a<br \/>\n\u300e<span style=\"color: #ff0000;\">\u4f60\u6709\u5169\u500b\u539f\u56e0\u4f86\u8b80\u9019\u672c\u66f8\uff1a\u9996\u5148\u4f60\u662f\u500b\u7a0b\u5f0f\u8a2d\u8a08\u5e2b\uff0c\u63a5\u8005\uff0c\u4f60\u60f3\u6210\u70ba\u4e00\u500b\u66f4\u597d\u7684\u8a2d\u8a08\u5e2b<\/span>\u300f<br \/>\n\u6211\u81ea\u5df1\u52a0\u4e0a\u53bb\u7684\uff1a\u300e\u525b\u597d\uff0c\u597d\u7684\u8a2d\u8a08\u5e2b\u85aa\u6c34\u597d\u50cf\u9084\u80fd\u770b\u300f<br \/>\n\uff08p1\uff09<\/p>\n<p>\u9019\u88e1\u5077\u5077\u5de5\u5546\u6642\u9593\u4e00\u4e0b\uff0c\u5c0f\u5f1f\u5beb\u4e86\u4e00\u500b\u7c21\u55ae\u7684 app <a href=\"https:\/\/play.google.com\/store\/apps\/details?id=com.heaton.funnyvote\">\u8da3\u6295\u7968<\/a>\u5e0c\u671b\u5927\u5bb6\u6709\u7a7a\u53ef\u4ee5\u5e6b\u5fd9\u73a9\u4e00\u4e0b\u3002\u958b\u767c\u5c0f\u6545\u4e8b<a href=\"https:\/\/boochlin.com\/?p=289\" rel=\"bookmark\">Funny Vote \u958b\u767c\u96dc\u8a18<\/a><br \/>\n<!--more--><\/p>\n<p>\u66f8\u6458\u5fc3\u5f97\uff1a<\/p>\n<h2>\u7b2c\u4e00\u7ae0\uff1a\u7121\u7455\u7684\u7a0b\u5f0f\u78bc<\/h2>\n<p>\u627f\u63a5&lt;\u5e8f&gt;\u7684\u90e8\u4efd\uff0c<span style=\"color: #ff0000;\">\u70ba\u4f55\u6211\u5011\u9700\u8981\u5beb\u51fa clean code:<\/span><\/p>\n<p>\u300e\u5728\u5927\u90e8\u4efd\u7684\u60c5\u6cc1\u4e0b\uff0c\u5982\u679c\u628a\u81ea\u5df1\u7684 coding \u904e\u7a0b\u7d66\u9304\u4e0b\u4f86\u7684\u8a71\uff0c\u6703\u767c\u73fe\u4ee5\u4e0b\u884c\u70ba<br \/>\nHeaton \u6253\u958b\u7a0b\u5f0f\u78bc<br \/>\n\u627e\u5230\u8981\u4fee\u6539\u7684\u51fd\u5f0f\uff0c\u958b\u59cb\u60f3\u60f3\u8981\u6539\u5565<br \/>\n\u5411\u4e0a\u6372\uff0c\u6aa2\u67e5\u51fd\u6578\u7684\u521d\u59cb\u72c0\u6cc1<br \/>\n\u5411\u4e0b\u5377\u56de\u525b\u525b\u7684\u51fd\u5f0f\uff0c\u958b\u59cb\u6539\u4e00\u6539<br \/>\n\u963f\uff0c\u53c8\u522a\u6389\u525b\u525b\u7684\u7a0b\u5f0f\u78bc\uff0c\u518d\u8f38\u5165\u4e00\u6b21\uff0c\u518d\u4e00\u6b21\u522a\u6389<br \/>\n\u767c\u73fe\u8ddf\u5176\u4ed6\u51fd\u5f0f\u6709\u95dc\u4fc2\uff0c\u6372\u5230\u525b\u525b\u7684\u51fd\u6578\uff0c\u770b\u4e86\u4e00\u4e0b\u8981\u600e\u67d0\u547c\u53eb<br \/>\n\u56de\u5230\u525b\u525b\u7684\u51fd\u5f0f\uff0c\u91cd\u65b0\u4fee\u6539\uff0c\u767c\u73fe\u6253\u932f\uff0c\u518d\u522a\u6389\uff0c\u53c8\u589e\u52a0\u300f<br \/>\n\uff08p.15\uff09<br \/>\n\u524d\u9762\u9019\u4e00\u6bb5\u8a71\u5b8c\u5168\u53ef\u4ee5\u7528\u500b\u8ff4\u5708\u7d66\u5305\u8d77\u4f86\uff0c\u56e0\u70ba\u53ea\u6703\u4e0d\u65b7\u5730\u91cd\u8907<br \/>\n\u4ee5\u9019\u6a23\u7684\u8a18\u9304\u4f86\u770b\uff0c\u5176\u5be6\u82b1\u8cbb\u5728\u95b1\u8b80\u7a0b\u5f0f\u8ddf\u64b0\u5beb\u7a0b\u5f0f\u7684\u6642\u9593\u5927\u6982\u662f\uff11\uff10\uff1a\uff11<\/p>\n<p><span style=\"color: #0000ff;\">\u6240\u4ee5\u8aaa\u5982\u679c\u628a\u6280\u80fd\u9ede\u6578\u9ede\u5728\u95b1\u8b80\u7a0b\u5f0f\u7684\u6280\u80fd\u4e0a\uff0c\u6703\u6bd4\u9ede\u5728\u5beb\u7a0b\u5f0f\u9019\u6280\u80fd<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u5728\u958b\u767c\u4e0a\uff0c\u6548\u76ca\u597d\u5f88\u591a\uff0c\u6240\u4ee5\u4e00\u958b\u59cb\u5c31\u628acode \u5beb\u5f97\u80fd\u770b\uff0c\u4fdd\u6301\u6574\u6f54\uff0c\u5c0d\u65bc\u4e4b\u5f8c\u7684\u958b\u767c\u7d55\u5c0d\u662f\uff11\uff10\u500d\u6578\u7684\u5f71\u97ff<\/span><\/p>\n<h2>\u7b2c\u4e8c\u7ae0\uff1a\u6709\u610f\u7fa9\u7684\u547d\u540d<\/h2>\n<p><span style=\"color: #0000ff;\">\u8981\u6709\u610f\u7fa9\u7684\u5340\u5206<\/span><\/p>\n<p>\u8acb\u554f\u4ee5\u4e0b\u4e09\u500b\u51fd\u6578\u8981\u505a\u7684\u4e8b\u60c5\u4f60\u5206\u7684\u51fa\u4f86\u55ce\uff1f<br \/>\n1. getActitiveAccount();<br \/>\n2. getActitiveAccounts();<br \/>\n3. getActitiveAccountInfo();<br \/>\n\u8acb\u76e1\u91cf\u907f\u514d\u9019\u6a23\u66d6\u6627\u7684\u547d\u540d<br \/>\n\uff08p.23\uff09<\/p>\n<h3>\u6210\u54e1\u7684\u5b57\u9996\uff1a<\/h3>\n<h4>2.1 \u00a0\u5168\u57df\u8b8a\u6578:<\/h4>\n<p>\u5f88\u591a\u60c5\u6cc1\u4e0b\uff0c\u6703\u5728\u5168\u57df\u8b8a\u6578\u7684\u524d\u9762\u52a0\u4e0a<span style=\"color: #0000ff;\"> m<\/span> \u6216\u8005 <span style=\"color: #0000ff;\">m_<\/span> \u9019\u4e00\u985e\u7684\u958b\u982d\uff0c\u4f86\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u52a0\u5bb9\u6613\u7684\u4fbf\u662f\u6b64\u8b8a\u6578\uff0c\u4f46\u5be6\u969b\u4e0a\u9019\u4e26\u6c92\u6709\u592a\u6709\u610f\u7fa9\uff0c\u5927\u90e8\u5206\u7684\u4eba\u9084\u662f\u53ea\u6703\u95b1\u8b80 <span style=\"color: #0000ff;\">m<\/span> \u4e4b\u5f8c\u6709\u610f\u7fa9\u7684\u547d\u540d\uff0c\u66f4\u4f55\u6cc1<span style=\"color: #0000ff;\">\u73fe\u5728\u7684ide \u90fd\u5df2\u7d93\u9032\u5316\u5230\uff0c\u53ef\u4ee5\u4e3b\u52d5\u628a \u5168\u57df\u8b8a\u6578\u81ea\u52d5\u63db\u8272 \u6240\u4ee5 m \u9019\u6a23\u7684\u5b57\u9996\u63d0\u793a\u5c31\u8b8a\u5f97\u53ea\u6703\u5e72\u64fe<\/span><br \/>\n\uff08p27\uff09<\/p>\n<p>\u672c\u4eba m \u7684\u7fd2\u6163\u7528\u6cd5\u5230\u73fe\u5728\u9084\u662f\u4e0d\u592a\u6703\u6539\uff0c\u9019\u5be6\u5728\u6709\u9ede\u898b\u4ec1\u898b\u667a<\/p>\n<h4>2.2 \u00a0\u4ecb\u9762\u548c\u5be6\u4f5c:<\/h4>\n<p>\u4ecb\u9762\u7684\u7684\u5ba3\u544a\u6642\uff0c\u4e0d\u5c11 open source project \u90fd\u6703\u7279\u5730\u52a0\u4e0a <span style=\"color: #0000ff;\">I<\/span> \u9019\u6a23\u7684\u958b\u982d\uff0c\u4f8b\u5982 <span style=\"color: #0000ff;\">I<\/span>ImageBackView\uff0c\u85c9\u6b64\u544a\u77e5\u958b\u767c\u8005\u9019\u662f\u4e00\u500b\u4ecb\u9762\uff0c\u4f46\u9019\u500b <span style=\"color: #0000ff;\">I<\/span> \u540c\u6a23\u4e5f\u53ea\u6709\u8b93\u4eba\u5206\u5fc3\u7684\u529f\u80fd\uff0c\u958b\u767c\u8005\u6839\u672c\u4e0d\u5728\u610f\u662f\u4e0d\u662f\u4ecb\u9762\uff0c\u800c\u662f\u5728\u610f\u9019 ImageBackView \u5230\u5e95\u662f\u600e\u6a23\u7684 view\uff0c<span style=\"color: #ff0000;\">\u5982\u679c\u771f\u7684\u60f3\u8981\u5340\u5206 interface \u9084\u662f implement \uff0c\u90a3\u6703\u6bd4\u8f03\u5efa\u8b70\u5728\u5be6\u4f5c\u7aef\u6539\u6210 ImageBackViewImpl\u3002<\/span><br \/>\n(p28)<\/p>\n<h4>2.3 \u6bcf\u7a2e\u6982\u5ff5\u4f7f\u7528\u4e00\u7a2e\u5b57\u8a5e\uff1a<\/h4>\n<p><span style=\"color: #0000ff;\">\u5728\u540c\u4e00\u500b\u5c08\u6848\u6642\uff0c\u76e1\u53ef\u80fd\u7684\u5728\u67d0\u4e9b\u95dc\u9375\u5b57\u4fdd\u6301\u4e00\u81f4<\/span>\uff0c\u4f8b\u5982\u5728\u53d6\u5f97\u8cc7\u6599\u6642\u51fd\u5f0f\u547d\u540d <span style=\"color: #0000ff;\">fetchXXX , getXXX , retrieveXXX<\/span> \u9019\u5e7e\u500b\u958b\u982d\uff0c\u8981\u5340\u5206\u958b\u4f86\uff0c\u6216\u662f\u7d71\u4e00\u53ea\u7528\u4e00\u7a2e\uff0c<span style=\"color: #ff0000;\">\u7dad\u6301\u4e00\u81f4\u6027\uff0c\u8b93\u958b\u767c\u8005\u5728 search method \u6642\u53ef\u4ee5\u66f4\u5feb\u5730\u627e\u51fa\u95dc\u9375\u5b57\u3002<\/span><\/p>\n<p>\u540c\u6a23\u7684\u7528\u5728 class \u547d\u540d\uff0c\u4e00\u500b\u5c08\u6848\u88e1\u540c\u6642\u6709 <span style=\"color: #0000ff;\">XXXController , XXXManager , XXXDriver<\/span> \u5728\uff0c\u5c0d\u65bc\u958b\u767c\u8005\u4e5f\u53ea\u6703\u611f\u5230\u56f0\u60d1\uff0c\u9019\u5e7e\u7a2e\u5230\u5e95\u5dee\u5728\u54ea\u88e1\uff0c\u5982\u679c\u6c92\u6709\u5dee\u5230\u5929\u7ffb\u5730\u9060\uff0c\u7d71\u4e00\u8d77\u4f86\u53ea\u6703\u6709\u597d\u8655\uff0c\u9019\u88e1\u53ef\u4ee5<span style=\"color: #ff0000;\">\u914d\u5408\u6b63\u5728\u7528\u7684 design pattern \u7fd2\u6163\u7528\u540d\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u9032\u5165\u72c0\u6cc1<\/span>\u3002<br \/>\n\uff08p.30\uff09<br \/>\n\u500b\u4eba\u5728home \u958b\u767c\u6642\uff0c\u6211\u5c31\u5e38\u5e38\u540c\u6642\u4f7f\u7528 controller \u548c manager \u6df7\u7528\uff0c\u5f8c\u4f86\u89ba\u5f97\u597d\u50cf\u8b8a\u5f97\u4e0d\u597d\u8ddf\u8001\u5927\u8aaa\u660e\u54ea\u500b\u6771\u897f\u653e\u5728\u54ea\u500b class \uff0c\u90a3\u4e7e\u8106\u901a\u901a\u7528 manager \uff0c\u9019\u6a23\u6e9d\u901a\u6642\u4e5f\u65b9\u4fbf\u591a\u4e86\u3002<\/p>\n<h2>\u7b2c\u4e09\u7ae0\uff1a\u51fd\u5f0f<\/h2>\n<p><span style=\"color: #0000ff;\">\u7c21\u77ed\uff0c\u53ea\u505a\u4e00\u4ef6\u4e8b<\/span><\/p>\n<p>\u4e00\u6bb5\u7a0b\u5f0f\u78bc\uff0c\u5047\u8a2d\u505a\u4e86\u4e09\u4ef6\u4e8b\u60c5\uff0c\u6700\u597d\u628a\u9019\u4e09\u4ef6\u4e8b\u60c5\u5206\u958b\u7368\u7acb\u6210\u4e09\u500b\u51fd\u5f0f\uff0c\u7136\u5f8c\u7d66\u4e88\u6709\u610f\u7fa9\u7684\u547d\u540d\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u5feb\u7406\u89e3\u7a0b\u5f0f\u78bc<br \/>\n\u4ee5 home \u7684 BitmapVolleyManager \u7684\u90e8\u5206\u7a0b\u5f0f\u78bc\u4f86\u770b\uff08\u5982\u4e0b\uff09\uff0c\u4ee5\u4e0b load bitmap \u505a\u4e86\u4e09\u4ef6\u4e8b\u60c5<br \/>\n1. set view loading url and check url is valid.<br \/>\n2. get bitmap from image cache.<br \/>\n3. assign bitmap worker task for this view and url<\/p>\n<pre>public synchronized void loadBitmap(String imageUri, ImageBackView imageView\r\n            , BitmapConfiguration configuration, boolean stackKeep, boolean clearFirst) {\r\n\r\n        imageView.setKey(imageUri);\r\n        if (clearFirst)\r\n            imageView.setBitmap(null);\r\n        if (!Utils.isValid(imageUri)) {\r\n            Log.d(\"BitmapVolleyManager\", \"loadBitmap, image uri should not be null, cancel loading\");\r\n            return;\r\n        }\r\n\r\n        Bitmap bitmap = VolleyManager.getPageImageCache(mContext)\r\n                .getBitmap(ImageLoader.getCacheKey(imageUri, configuration.requestWidth\r\n                        , configuration.requestHeight, configuration.mScaleType));\r\n        if (bitmap != null) {\r\n            imageView.setBitmap(bitmap);\r\n            return;\r\n        }\r\n        final BitmapWorkerTask task = new BitmapWorkerTask(imageView, imageUri, configuration);\r\n        if (stackKeep) {\r\n            synchronized (this) {\r\n                mStackLoadTask.push(task);\r\n            }\r\n        } else {\r\n            Log.d(\"BitmapVolleyManager\", \"Add a Bitmap task ,image uri:\" + imageUri);\r\n            task.executeOnExecutor(getExecutorPool());\r\n        }\r\n    }\r\n<\/pre>\n<p>\u76f4\u63a5\u4f86\u770b\u4e5f\u4e26\u4e0d\u96e3\u61c2\uff0c\u4f46\u662f\u66f4\u9032\u4e00\u6b65\u4f86\u770b\u6216\u8a31\u53ef\u4ee5\u66f4\u52a0\u7368\u7acb\u6210<\/p>\n<pre>public synchronized void loadBitmap(String imageUri, ImageBackView imageView\r\n            , BitmapConfiguration configuration, boolean stackKeep, boolean clearFirst) {\r\n\r\n        checkViewForURL(imageuri, imageview);\r\n        \r\n        if (clearFirst)\r\n            imageView.setBitmap(null);\r\n\r\n        Bitmap bitmap = getBitmapFromCache(imageUri, configuration);\r\n        if (bitmap != null) {\r\n            imageView.setBitmap(bitmap);\r\n            return;\r\n        }\r\n        startNetworkBitmapLoadingTask(imageUri, imageView , configuration , stackkeep);     \r\n    }\r\npublic boolean checkViewURLIsValid(String targetURL, ImageBackView imageView) {\r\n    imageView.setKey(imageUri);\r\n    if (!Utils.isValid(imageUri)) {\r\n       Log.d(\"BitmapVolleyManager\", \"loadBitmap, image uri should not be null, cancel loading\");\r\n       return false;\r\n       }\r\n    } else {\r\n       return true;\r\n    }\r\n}\r\n\r\npublic Bitmap getBitmapFromCache(String targetURL , BitmapConfiguration configuration) {\r\n    Bitmap bitmap = VolleyManager.getPageImageCache(mContext)\r\n                .getBitmap(ImageLoader.getCacheKey(imageUri, configuration.requestWidth\r\n                        , configuration.requestHeight, configuration.mScaleType));\r\n    return bitmap;\r\n}\r\n\r\npublic void startNetworkBitmapLoadingTask(String targetURL , ImageBackView imageView , BitmapConfiguration configuration\r\n    , boolean stackKeep) {\r\n    final BitmapWorkerTask task = new BitmapWorkerTask(imageView, targetURL, configuration);\r\n        if (stackKeep) {\r\n            synchronized (this) {\r\n                mStackLoadTask.push(task);\r\n            }\r\n        } else {\r\n            Log.d(\"BitmapVolleyManager\", \"Add a Bitmap task ,image uri:\" + targetURL);\r\n            task.executeOnExecutor(getExecutorPool());\r\n        }\r\n}\r\n\r\n<\/pre>\n<p>\u597d\u5427\uff0c\u81f3\u5c11\u7b2c\u4e00\u968e\u6bb5\u7684\u539f\u5247\u5df2\u7d93\u4fee\u6b63\u5b8c\u6210\u4e86\uff08\u96d6\u7136\u9084\u662f\u9055\u53cd\u5f88\u591a\u4e4b\u5f8c\u6703\u8ac7\u5230\u7684\u539f\u5247\uff0c\u63d0\u5230\u6642\u518d\u6539\uff09<br \/>\n(p40.41)<\/p>\n<h3>3.1 switch \u6558\u8ff0\uff1a<\/h3>\n<p><span style=\"color: #0000ff;\">\u8981 switch \u7c21\u77ed\uff0c\u4e26\u4e0d\u5bb9\u6613\uff0c\u56e0\u70baswitch \u7e3d\u662f\u6703\u9055\u53cd\u300e\u55ae\u4e00\u539f\u5247\uff08single responsibility principle\uff09\u300f<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u548c \u300e\u958b\u653e\u9589\u548c\u539f\u5247\uff08open closed principle\uff09\u300f<\/span>\uff0c\u8a73\u7d30\u7a0b\u5f0f\u78bc\u7684\u7bc4\u4f8b\u9084\u662f\u770b\u66f8\u6bd4\u8f03\u597d\u3002<br \/>\n\u7c21\u55ae\u4f86\u8aaa\u5c31\u662f switch \u7684\u7528\u6cd5\u5f80\u5f80\u7d81\u5b9a\u7279\u6b8a\u503c\uff0c\u4f8b\u5982 <span style=\"color: #0000ff;\">enum<\/span> \u00a0, \u9019\u6a23\u5728\u8981\u64f4\u589e\u7684\u6642\u5019\uff0c\u52e2\u5fc5\u8981\u5230\u8655\u4fee\u6539\u7528\u5230\u7684\u5730\u65b9\u3002\u53ef\u662f\u66f8\u4e2d\u4e5f\u63d0\u5230\u9019\u662f\u5fc5\u8981\u4e4b\u60e1\uff0c\u5982\u679c\u53ef\u4ee5\u7684\u8a71\uff0c\u6700\u597d\u4e00\u5927\u6bb5\u7a0b\u5f0f\u78bc\uff0c\u5c31\u53ea\u6709\u4e00\u500b<span style=\"color: #0000ff;\">switch<\/span> \u5c31\u597d\uff0c\u5269\u4e0b\u7684\u7528\u591a\u578b\u7d66\u8655\u7406\u6389\u3002<br \/>\n\uff08p.44\uff09<\/p>\n<h3>3.2 \u51fd\u5f0f\u7684\u53c3\u6578\uff1a<\/h3>\n<p><span style=\"color: #0000ff;\">\u51fd\u5f0f\u7684\u6700\u4f73\u53c3\u6578\u6578\u91cf\uff0c\u6700\u7406\u60f3\u7684\u662f\u96f6\u500b\uff0c\u5176\u6b21\u662f\u4e00\u500b\uff0c\u63a5\u4e0b\u4f86\u662f\u5169\u500b\uff0c\u597d\u5427\u4e09\u500b\u662f\u6975\u9650\uff0c\u5225\u518d\u4e0a\u53bb\u4e86\uff0c\u56e0\u70ba\u53c3\u6578\u672c\u8eab\u4e5f\u662f\u4e00\u7a2e\u6982\u5ff5\u7684\u50b3\u9054\u3002<\/span><br \/>\n\u4e0b\u9762\u5169\u500b\u51fd\u5f0f\u54ea\u500b\u6bd4\u8f03\u597d\u7406\u89e3<br \/>\nincludeSetupPageInfo(newPageContent);<br \/>\nincludeSetupPage();<\/p>\n<p><span style=\"color: #0000ff;\">\u57fa\u672c\u4e0a\u53c3\u6578\u548c\u51fd\u5f0f\u540d\u7a31\u662f\u5c6c\u65bc\u4e0d\u540c\u5206\u5340\uff0c\u7406\u89e3\u4e0a\u662f\u6703\u6bd4\u8f03\u56f0\u96e3\u4e00\u4e9b\uff0c\u7121\u6cd5\u4e00\u773c\u5c31\u5feb\u901f\u91d0\u6e05\uff0c\u53c3\u6578\u548c\u51fd\u5f0f\u7684\u95dc\u4fc2\uff0c\u800c\u4e14\u53c3\u6578\u6703\u5f37\u8feb\u958b\u767c\u8005\u53bb\u7406\u89e3\u4e0d\u5fc5\u8981\u7684\u8cc7\u8a0a\uff0c\u56e0\u70ba\u958b\u767c\u8005\u6703\u53bb\u64d4\u5fc3\u9019\u53c3\u6578\u5230\u5e95\u6703\u5f71\u97ff\u5230\u5565\uff0c\u53c8\u8a72\u600e\u67d0\u8655\u7406\uff0c\u6b64\u5916\uff0c\u53c3\u6578\u8d8a\u591a\uff0c\u6e2c\u8a66\u7684\u8907\u96dc\u5ea6\u66f4\u6703\u6307\u6578\u578b\u4e0a\u5347\u3002<\/span><br \/>\n(p.47)<\/p>\n<p><span style=\"color: #0000ff;\">\u8f38\u51fa\u578b\u53c3\u6578\u7684\u8a2d\u8a08<\/span>\u66f4\u662f\u4e00\u5927\u96e3\u4ee5\u7406\u89e3\u9ede\uff0c\u5927\u90e8\u5206\u958b\u767c\u8005\u5c0d\u65bc\u51fd\u5f0f\u7684\u7406\u89e3\u901a\u5e38\u90fd\u662f\u5f9e\u53c3\u6578\u8f38\u5165\u8cc7\u6599\uff0c\u7136\u5f8c\u518dreturn \u88e1\u5f97\u5230\u8f38\u51fa\u8cc7\u6599\u3002\u4e00\u822c\u60c5\u6cc1\u4e0b\u6839\u672c\u4e0d\u6703\u60f3\u5230\u6703\u7528\u653e\u5728\u53c3\u6578\u7684\u8cc7\u6599\u505a\u70ba\u50b3\u905e\u7684\u5de5\u5177\u3002<br \/>\n\uff08\u672c\u4eba\u9019\u9ede\u6df1\u611f\u75db\u82e6\uff0c\u8001\u662f\u6709\u4eba\u628a list \u653e\u9032\u53c3\u6578\u88e1\uff0c\u7136\u5f8c\u76f4\u63a5\u5c0d list \u64cd\u4f5c\uff0c\u4e00\u822c\u6211\u5728 trace \u90fd\u6703\u611f\u5230\u56f0\u60d1\uff0c\u60f3\u8aaa\u5565\u6642\u9019list \u88ab\u6539\u904e\u4e86\uff09<\/p>\n<pre>List output = sortByTime(input);\r\n\u5e95\u4e0b\u7684\u5beb\u6cd5\u771f\u7684\u5f88\u5bb9\u6613\u56f0\u60d1\r\nsortByTime(input);\r\n<\/pre>\n<p>(p.52)<\/p>\n<h4>3.2.1 \u55ae\u4e00\u7684\u53c3\u6578<\/h4>\n<p>\u9019\u4e00\u5c0f\u6bb5\uff0c<span style=\"color: #ff0000;\">\u4f5c\u8005\u5341\u5206\u53cd\u5c0d\u4f7f\u7528 flag \u4f5c\u70ba\u53c3\u6578<\/span><br \/>\n\u4e3b\u56e0\u70ba boolean is true \u6703\u505a\u7b2c\u4e00\u7a2e\u4e8b\uff0c\u90a3 false \u5c31\u6703\u505a\u7b2c\u4e8c\u7a2e\u4e8b<br \/>\n\u5f88\u660e\u986f\u5730\u9055\u53cd\u55ae\u4e00\u539f\u5247\uff0c\u4ee5\u4e0a\u9762\u7684\u4f8b\u5b50\u5c31\u662f<\/p>\n<pre>public synchronized void loadBitmap(String imageUri, ImageBackView imageView\r\n            , BitmapConfiguration configuration, boolean stackKeep, boolean clearFirst)\r\n<\/pre>\n<p>\u9019\u88e1\u9762\u7684 stackKeep , clearFirst<br \/>\n\u9019\u5169\u500b\u53c3\u6578\u5206\u5225\u662f\uff0c\u8b80\u53d6\u5716\u7247\u4efb\u52d9\uff0c\u5148\u653e\u5728stack \u7b49\u5f85\u5176\u4ed6\u6642\u9593\uff0c\u5728\u958b\u59cb\u555f\u52d5\u4efb\u52d9\u548c \u5148\u6e05\u9664 ImageView \u4e0a\u9762\u7684\u5716\u7247\uff0c\u5728\u8f09\u5165\u5716\u7247<br \/>\n\u8001\u5be6\u8aaa\u53ea\u770b\u9019\u53c3\u6578\u540d\u7a31\u5e7e\u4e4e\u4e0d\u61c2\u5565\u610f\u7fa9<br \/>\n(p.48)<br \/>\n\uff08\u4e0d\u904e\u6211\u500b\u4eba\u4e26\u4e0d\u662f\u90a3\u67d0\u53cd\u5c0d\u55ae\u4e00 boolean \u53c3\u6578\u7684\u8a2d\u8a08\uff0c\u56e0\u70ba\u4efb\u4f55\u5f48\u6027\u7684\u8a2d\u8a08\u518d\u591a\u5f62\u7684\u57fa\u790e\u4e0a<br \/>\n\u7e3d\u6703\u6709\u500b method \u662f\u6700\u5927\u53c3\u6578\u96c6\u5408\uff0c\u5982\u4e0b\uff0c\u56e0\u6b64\u53ea\u8981\u7279\u5730\u628a\u53c3\u6578\u9084\u6709\u51fd\u5f0f\u529f\u80fd\u7684\u8a3b\u89e3\u5beb\u597d\u5c31\u53ef\u4ee5\u4e86\uff0c\u4e0d\u904e\u4e4b\u5f8c\u7684\u7ae0\u7bc0\u4e5f\u6703\u63d0\u5230\u4f5c\u8005\u4e26\u4e0d\u559c\u6b61\u8a3b\u89e3\uff09<\/p>\n<pre>    \/**\r\n    \r\n    **\/\r\n    public void loadBitmap(String imageUri, ImageBackView imageView) {\r\n        loadBitmap(imageUri, imageView, new BitmapConfiguration(DEFAULT_LEFT_ITEM_WIDTH, DEFAULT_LEFT_ITEM_HEIGHT), false, true);\r\n    }\r\n\r\n    public void loadBitmapStackKeep(String imageUri, ImageBackView imageView, BitmapConfiguration configuration) {\r\n        loadBitmap(imageUri, imageView, configuration, true, true);\r\n    }\r\n    public synchronized void loadBitmap(String imageUri, ImageBackView imageView\r\n            , BitmapConfiguration configuration, boolean stackKeep, boolean clearFirst) {\r\n<\/pre>\n<h4>3.2.2 \u7269\u4ef6\u578b\u614b\u7684\u53c3\u6578<\/h4>\n<p><span style=\"color: #0000ff;\">\u8d85\u904e\u5169\u500b\u4e09\u500b\u7684\u53c3\u6578\u6642\uff0c\u5f88\u53ef\u80fd\u9700\u8981\u5c07\u5176\u4e2d\u5e7e\u500b\u7d44\u5408\u6210\u4e00\u500b\u985e\u5225\uff0c\u770b\u8d77\u4f86\u5f88\u50cf\u53ea\u662f\u898f\u907f\u53c3\u6578\u6578\u91cf\u76e1\u91cf\u5c11\u7684\u539f\u5247<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u5176\u5be6\u4e26\u4e0d\uff0c\u9019\u5b8c\u5168\u53ef\u4ee5\u5e6b\u52a9\u958b\u6cd5\u8005\u53bb\u7406\u89e3\u53c3\u6578\u7684\u7406\u5ff5\uff0c<\/span>\u4ee5\u4e0a\u9762\u4f8b\u5b50\u4f86\u770b \u5c31\u662f BitmapConfiguration \u88e1\u9762\u5305\u542b\u5bec\u9ad8\uff0c\u7e2e\u653e\u985e\u578b<br \/>\n\u6216\u8a31\u53ef\u4ee5\u518d\u628a stack keep \u548c clearfirst \u52a0\u9032\u53bb\uff0c\u4e0d\u904e\u500b\u4eba\u89ba\u5f97\u52a0\u9032\u53bb\u7684\u8a71\u5c31\u4e0d\u80fd\u7528BitmapConfiguration \u800c\u662f\u4f7f\u7528<br \/>\nLoadConfiguration \u6703\u6bd4\u8f03\u597d\uff0c\u7136\u5f8c\u5305\u542bBitmapConfiguration and stackkeep and clearfirst.<br \/>\n(\u53ef\u662f\u8001\u6a23\u5b50\uff0c\u6211\u89ba\u5f97\u9019\u6709\u9ede\u898b\u4ec1\u898b\u667a)<br \/>\nbook example:<\/p>\n<pre>Circle makeCircle(double x , double y , double radius);\r\nCircle makeCircle(Point center , double radius);\r\n<\/pre>\n<p>(p.50)<\/p>\n<h3>3.3 \u4f7f\u7528\u4f8b\u5916\u8655\u7406\u4ee3\u66ff\u56de\u50b3\u932f\u8aa4\u78bc<\/h3>\n<p><span style=\"color: #0000ff;\">\u4f7f\u7528try\/catch\uff0c\u4e26\u5728 catch \u628a\u5f8c\u7e8c\u8655\u7406\u5b8c\u6210\uff0c\u800c\u4e0d\u8981\u7528\u56de\u50b3\u932f\u8aa4\u78bc\u7684\u65b9\u5f0f\uff0c\u9019\u4ee3\u8868\u8005\u4e8b\u60c5\u5f80\u5f8c\u9762\u4e1f\uff0c\u5f62\u6210\u66f4\u6df1\u5c64\u7684\u5de2\u72c0\u7d50\u69cb\uff0c\u5c24\u5176\u662f\u81ea\u5b9a\u7fa9\u7684 enum error code.<\/span><\/p>\n<h3>3.4 \u628a try\/catch \u5340\u584a\u63d0\u53d6\u51fa\u4f86<\/h3>\n<p><span style=\"color: #0000ff;\">\u5728 try\/catch \u5340\u584a\u5167\u6700\u597d\u5c31\u53ea\u6709\u4e00\u884c\u51fd\u5f0f\uff0c\u7136\u5f8c\u628acode\u5beb\u5728\u51fd\u5f0f\u88e1<\/span><br \/>\n\uff08p.54\uff09<\/p>\n<p><span style=\"color: #0000ff;\">\u5c11\u7528 break , continue\uff0c\u4fdd\u6301\u6548\u7387\u53ef\u4ee5\u659f\u914c\u4f7f\u7528<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u9084\u6709\u7d55\u5c0d\u4e0d\u8981\u7528 goto\uff0c\u9019\u53ea\u6703\u8b93\u770b\u7684\u4eba\u75db\u82e6<\/span><\/p>\n<pre>while (condition1) {\r\n  xxx\r\n    if (condition2) {\r\n      break;\r\n    }\r\n}\r\n<\/pre>\n<p>\u63db\u6210\u4e0b\u9762\uff0c\u9019\u6a23\u660e\u986f\u597d\u591a\u4e86<\/p>\n<pre>while (condition1 &amp;&amp; !condition2) {\r\n  xxx\r\n}\r\n<\/pre>\n<p>\u81f3\u65bccontinue\uff0c\u600e\u67d0\u4e0d\u8003\u616e\u4e00\u4e0b\u628a\u689d\u4ef6\u5f0f\u53cd\u8f49\u4e00\u4e0b<\/p>\n<pre>List goodNames = new ArrayList&lt;&gt;();\r\nfor (String name: names) {\r\n    if (name.contains(\"bad\")) {\r\n       continue;\r\n    }\r\n    goodNames.add(name);\r\n    ...\r\n}\r\n<\/pre>\n<p>\u6539\u5beb\u4e00\u4e0b<\/p>\n<pre>List goodNames = new ArrayList&lt;&gt;();\r\nfor (String name: names) {\r\n    if (!name.contains(\"bad\")) {\r\n       goodNames.add(name);\r\n       ...\r\n    }\r\n}\r\n<\/pre>\n<p>\u4e0a\u9762\u5169\u6bb5code , reference :<br \/>\n<a href=\"http:\/\/www.jianshu.com\/p\/7645a5ea7f46?utm_content=buffer50622\">http:\/\/www.jianshu.com\/p\/7645a5ea7f46?utm_content=buffer50622<\/a><br \/>\n\uff08p.57\uff09<\/p>\n<h2>\u7b2c\u56db\u7ae0 \u8a3b\u89e3<\/h2>\n<p><span style=\"color: #0000ff;\">\u6c92\u6709\u4efb\u4f55\u6771\u897f\u53ef\u4ee5\u6bd4\u4e00\u6bb5\u653e\u5c0d\u4f4d\u7f6e\u7684\u8a3b\u89e3\u9084\u6709\u7528\uff0c\u4f46\u662f\u653e\u932f\u5730\u65b9\u7684\u8a3b\u89e3\uff0c\u66f4\u53ef\u4ee5\u5f04\u4e82\u6a21\u7d44\u5316\uff0c<\/span><span style=\"color: #0000ff;\">\u66f4\u5225\u8aaa\u5beb\u932f\u7684\u8a3b\u89e3\uff0c\u9019\u6839\u672c\u662f\u8b20\u8a00\u7522\u751f\u5668<\/span><br \/>\n\uff08p.61\uff09<\/p>\n<h3>4.1 \u8a3b\u89e3\u6c92\u8fa6\u6cd5\u5f4c\u88dc\u7cdf\u7cd5\u7684\u7a0b\u5f0f\u78bc<\/h3>\n<p><span style=\"color: #0000ff;\">\u5982\u679c\u7a0b\u5f0f\u78bc\u5df2\u7d93\u9ad2\u4e82\u5230\u5fc5\u9808\u5beb\u4e00\u5927\u5806\u8a3b\u89e3\u4f86\u641e\u6e05\u695a\u610f\u5716\uff0c\u90a3\u8acb\u91cd\u5beb\u4f60\u7684\u7a0b\u5f0f\u78bc\uff0c\u8b93\u4ed6\u66f4\u6574\u6f54\uff0c\u9032\u800c\u4e0d\u9700\u8981\u90a3\u4e00\u5806\u96e3\u641e\u7684\u8a3b\u89e3<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u6574\u6f54\u7684\u7a0b\u5f0f\u78bc\u7d55\u5c0d\u597d\u904e\u4e00\u5927\u5806\u7684\u8a3b\u89e3\uff0c\u6700\u9ad8\u5883\u754c\u5c31\u662f\u4e0d\u7528\u8a3b\u89e3<\/span><br \/>\n\uff08p.63\uff09<\/p>\n<h4><strong>4.1.1 \u7576\u7136\u4e5f\u662f\u6709\u5fc5\u8981\u6216\u597d\u7684\u8a3b\u89e3<\/strong><\/h4>\n<p>\uff11\uff0e\u6cd5\u5f8b\u5f62\u7248\u6b0a\u5ba3\u544a<\/p>\n<p>\uff12\uff0e\u51fd\u5f0f\u540d\u7a31\u591a\u5230\u4e0d\u884c\uff0c\u5f04\u500b\u6709\u5206\u5b57\u7684\u8a3b\u89e3\u6bd4\u8f03\u597d\u61c2<\/p>\n<p>\uff13\uff0e\u89e3\u91cb\u81ea\u5df1\u8a2d\u8a08\u7684\u610f\u5716\u60f3\u6cd5\uff0c\u4f8b\u5982\u51fd\u5f0f\u7684\u9806\u5e8f\uff0c\u6216\u662f\u7279\u6b8a\u7684spec request.<\/p>\n<p>\uff14\uff0e\u51fd\u5f0f\u5eab\u88e1\u7684\u51fd\u5f0f\u771f\u7684\u592a\u8a6d\u7570\uff0c\u4f46\u662f\u6211\u5011\u4e0d\u80fd\u53bb\u4fee\u6539\u51fd\u5f0f\u5eab\u7684\u51fd\u5f0f\u540d\u7a31\uff0c\u53ea\u597d\u81ea\u5df1\u5728\u4f7f\u7528\u6642\uff0c\u8aaa\u6e05\u695a<\/p>\n<p>\uff15\uff0eside effect \u7684\u63d0\u793a<\/p>\n<p>\uff16\uff0eTODO \u7684\u8a3b\u89e3\uff0c\u9019\u6700\u9ad8\u5883\u754c\u5c31\u662f\u5168\u90e8\u6e05\u6389\uff0c\u4f46\u662f\u6211\u5011\u4e5f\u77e5\u9053\u9019\u4e0d\u592a\u53ef\u80fd\uff0c\u4f7f\u7528TODO\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u5feb\u901f\u627e\u5230\u4fee\u6539\u9ede<\/p>\n<h4><strong>4.1.2 \u7cdf\u7cd5\u7684\u8a3b\u89e3<\/strong><\/h4>\n<p>\uff11\uff0e\u795e\u79d8\u8a3b\u89e3\uff0c\u53ea\u6709\u4f60\u770b\u5f97\u61c2\u7684\u6587\u5b57<\/p>\n<p>\uff12\uff0e\u5beb\u592a\u9577\u8a3b\u89e3\uff0c\u770b\u4f60\u7684\u8a3b\u89e3\u53ef\u80fd\u80fd\u6bd4\u770b\u4f60\u7a0b\u5f0f\u78bc\u9084\u8981\u6d6a\u8cbb\u6642\u9593\u7684\u8a3b\u89e3, html \u5f0f\u7684\u8a3b\u89e3\uff0c\u89e3\u91cb rfc \u6587\u4ef6\u7de8\u78bc\u6a21\u5f0f\u554a\uff0c\u7406\u89e3\u8d77\u4f86\u53c8\u7d2f\u53c8\u4e0d\u9700\u8981<\/p>\n<p>\uff13\uff0e\u8aa4\u5c0e\u5f62\u8a3b\u89e3\uff0c\u9019\u53ef\u80fd\u662f\u6b77\u53f2\u5171\u696d\uff0c\u62dc\u8a17\u5feb\u522a\u6389<\/p>\n<p>\uff14\uff0e\u898f\u5b9a\u884c\u8a3b\u89e3\uff0c\u4f8b\u5982 java doc \u7684\u898f\u5b9a\u683c\u5f0f\uff0c\u6bcf\u500b\u90fd\u8981\u5beb\u771f\u7684\u8822\u7206\u4e86<\/p>\n<p>\uff15\uff0e\u65e5\u8a8c\u5f62\u8a3b\u89e3\uff0c\u8001\u5be6\u8aaa\u9019\u5728\u6c92\u6709 git \u7684\u6642\u4ee3\u9084\u6709\u7406\u7531\uff0c\u4f46\u73fe\u5728\u7528 commit message \u53bb\u53d6\u4ee3\u4e0d\u662f\u5f88\u597d\u55ce\uff1f\u4f5c\u8005\u8ddf\u51fa\u8655\u6c92\u898f\u5b9a\u7684\u8a71\u4e5f\u662f\u540c\u6a23<\/p>\n<p>\uff16\uff0e\u5e72\u64fe\u5f62\u8a3b\u89e3\uff0c\u5c31\u662f\u5ee2\u8a71\uff0c\u5beb\u932f\u5730\u65b9\u554a\uff0c\u5168\u57df\u548c\u5340\u57df\u7684\u8a3b\u89e3\u8981\u5206\u6e05\u695a<\/p>\n<p>\uff17\uff0e\u88ab\u8a3b\u89e3\u8d77\u4f86\u7684\u7a0b\u5f0f\u78bc<br \/>\n<span style=\"color: #3366ff;\">\u9019\u500b\u6211\u89ba\u5f97\u8981\u5927\u529b\u63d0\u5021\uff0c\u901a\u5e38\u4f60\u8a3b\u89e3\u8d77\u4f86\u7684\u7a0b\u5f0f\u78bc\uff0c\u5176\u4ed6\u4eba\u90fd\u6703\u4ee5\u70ba\u5f88\u91cd\u8981\uff0c\u7136\u5f8c\u4e0d\u6562\u53bb\u522a\u6389\uff0c\u5176\u4ed6\u90fd\u6703\u4ee5\u70ba\u7559\u8005\u5fc5\u6709\u539f\u56e0\uff0c\u6700\u5f8c\u5c31\u8b8a\u6210\u985e\u4f3c\u9ef4\u83cc\u7684\u6771\u897f\uff0c\u5be6\u969b\u4e0a\u9019\u5728\u6c92 git \u7684\u6642\u4ee3\u6216\u8a31\u53ef\u4ee5\u5e6b\u52a9\u628a code \u4fdd\u7559\u8457\uff0c\u4f46\u662f\u73fe\u5728\u6709\u7248\u672c\u63a7\u5236\u4e86\uff0c\u8acb\u76f4\u63a5\u522a\u6389\u3002<\/span><br \/>\n<span style=\"color: #3366ff;\"> \uff08\u9019\u500b\u53ef\u4ee5\u5927\u529b\u63a8\u5ee3\uff0c\u8001\u5be6\u8aaa\u8a3b\u89e3\u8d77\u4f86\u5230\u6700\u5f8c\u7684\u4e0b\u5834\u90fd\u53ea\u662f\u5fd8\u4e86\u522a\uff0c\u800c\u4e14\u96a8\u8005\u958b\u767c\uff0c\u90a3\u4e9b\u88ab\u8a3b\u89e3\u7684\u7a0b\u5f0f\u78bc\u4e00\u9ede\u90fd\u4e0d\u91cd\u8981\uff09<\/span><\/p>\n<p>\u63a5\u4e0b\u4f86\u6211\u4f86\u8868\u6f14\u4e00\u6bb5\u7cdf\u7cd5\u7684\u4ee3\u78bc\uff0c\u81f3\u65bc\u5982\u4f55 refactor \u8acb\u81ea\u5df1\u7df4\u7fd2\u5427\uff1a<\/p>\n<pre>\/**\r\n * changes (from 11-OCT-2009 ) author : heaton\r\n *\r\n * Add a CD with title , author , number , like celine.\r\n * @param title The title of the CD\r\n * @param author The author of the CD\r\n * @param tracks The number of tracks on the CD\r\n*\/\r\npublic void addCD(String title , String author , int tracks) {\r\n   \/\/ new CD for add to total list.\r\n   CD cd  = new CD();\r\n   cd.title = title;\r\n   cd.author = author;\r\n   \/\/ size mean the cd duration from start to end.\r\n   \/\/cd.size = size;\r\n   cd.tracks = tracks;\r\n   cdList.add(cd);\r\n}\r\n\r\n<\/pre>\n<p>\u4e0a\u9762\u7684\u5410\u69fd\u9ede\u771f\u7684\u592a\u591a\u4e86\uff0c\u8acb\u597d\u597d\u6aa2\u8996\u73fe\u5728\u624b\u4e0a\u7684\u5c08\u6848<br \/>\n\uff08p.63-77\uff09<\/p>\n<h2>\u7b2c\u4e94\u7ae0 \u7de8\u6392<\/h2>\n<p><span style=\"color: #0000ff;\">\u7a0b\u5f0f\u7684\u7de8\u6392\u5f88\u91cd\u8981\uff0c\u7dad\u6301\u4e00\u5b9a\u7684\u5718\u968a\u898f\u5247\u9032\u884c\u7de8\u6392\u7d55\u5c0d\u53ef\u4ee5\u52a0\u901f\u95b1\u8b80<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u66f4\u91cd\u8981\u7684\u662f \u53ea\u8981\u78ba\u7acb\u597d\u5718\u968a\u898f\u5247\u5f8c\uff0c\u81ea\u52d5\u5316\u5de5\u5177\u53ef\u4ee5\u5e7e\u4e4e\u7121\u75db\u5c0e\u5165\uff0ccp\u503c\u6975\u9ad8<\/span><br \/>\n(P.86)<\/p>\n<h3>\u500b\u4eba\u89ba\u5f97\u9019\u6bb5\u9084\u597d\uff0c\u4e3b\u8981\u5c31\u662f\u5169\u500b\u91cd\u9ede<br \/>\n5.1\u6c34\u5e73\u8ddd\u96e2\uff1a<\/h3>\n<p>5.1.1 :\u7a0b\u5f0f\u78bc\u7684\u4efb\u4f55\u4e00\u884c\u4e0d\u61c9\u8a72\u592a\u9577\uff0c\u6700\u4f4e\u6700\u4f4e\u7684\u8981\u6c42\u5c31\u662f\u4e0d\u5f97\u8d85\u51fa\u87a2\u5e55\u9801\u9762\u5bec\u5ea6<br \/>\n\uff0c\u4fdd\u6301\u5728\u8996\u7dda\u7bc4\u570d\u5167\uff0c\u5982\u679c\u9700\u8981\u5de6\u53f3\u6ed1\u52d5\uff0c\u90a3\u80af\u5b9a\u9020\u6210\u56f0\u64fe<br \/>\n5.1.2\uff1a\u6bcf\u884c\u7684\u7a0b\u5f0f\u78bc\uff0c\u662f\u60c5\u6cc1\u4fdd\u6301\u7a7a\u767d\u884c\uff0c\u5598\u53e3\u6c23<br \/>\n(P.86)<\/p>\n<h3>5.2. \u5782\u76f4\u8ddd\u96e2\uff1a<\/h3>\n<p>5.2.1\uff1a\u8b8a\u6578\u5ba3\u544a\u4f4d\u7f6e\u7d71\u4e00\u653e\u7f6e\uff0cjava \u7fd2\u6163\u5168\u57df\u8b8a\u6578\u90fd\u653e\u5728\u6587\u4ef6\u6700\u4e0a\u7aef\uff0c\u800c\u5340\u57df\u8b8a\u6578\u5247\u76e1\u91cf\u9760\u8fd1\u4f7f\u7528\u4f4d\u5b50<br \/>\n5.2.2\uff1a\u76f8\u4f9d\u51fd\u5f0f\u76e1\u91cf\u9644\u8fd1\uff0c\u6700\u597d\u7684\u60c5\u6cc1\u5c31\u662f\uff0c\u53ef\u4ee5\u5f9e\u958b\u982d\u7684\u51fd\u5f0f\u9806\u9806\u5730\u5f80\u4e0b\u770b\uff0c\u800c\u4e0d\u9700\u8981\u5927\u7bc4\u570d\u7684\u6372\u52d5\u6ed1\u9f20<br \/>\n5.2.3\uff1a<span style=\"color: #0000ff;\">\u4fdd\u6301\u4e00\u5b9a\u7684\u7a7a\u767d\u884c\uff0c\u4eba\u5011\u559c\u6b61\u6709\u4e9b\u7559\u767d\u7684\u4eba\u751f<\/span><br \/>\n(P.90)<\/p>\n<p>\u9019\u4e00\u6bb5\u500b\u4eba\u89ba\u7684\uff0c\u4e0a\u9762\u7684\u6c34\u5e73\u548c\u5782\u76f4\u8ddd\u96e2\u7684\u898f\u5247\u90fd\u53ef\u4ee5\u9760IDE\u505a\u5230<br \/>\n\u4f46\u662f\u5171\u7528\u7684\u8b8a\u6578\u540d\uff0c\u6216\u662f\u6578\u503c\u5b9a\u7fa9\u7684\u4f4d\u5740\u8981\u78ba\u4e0d\u597d\u57f7\u884c<br \/>\n<span style=\"color: #3366ff;\">ex: \u50cf\u662f\u5e38\u898b\u7684 xxxSetting.java , xxxConstant.java , xxxDefine.java , \u9019\u4e00\u985e\u7684\u767e\u5bb6\u722d\u9cf4<\/span><br \/>\n<span style=\"color: #3366ff;\"> \u4e0d\u503c\u5f97\u9f13\u52f5\uff0c\u52e2\u5fc5\u8981\u6709\u4eba\u7d71\u4e00\u898f\u7bc4\u4e26\u6574\u7406\uff0c\u653e\u5728\u5dee\u4e0d\u591a\u7684\u8def\u5f91\u4e0b\uff0c\u4e26\u7528\u6b63\u78ba\u7684\u547d\u540d\u5e6b\u52a9\u95b1\u8b80<\/span><br \/>\n<span style=\"color: #3366ff;\"> \u9019\u9ede\u624b\u4e0a\u7684 Home \u5c08\u6848\uff0c\u4e5f\u6709\u540c\u6a23\u7684\u554f\u984c<\/span><\/p>\n<h2>\u7b2c\u516d\u7ae0 \u7269\u4ef6\u53ca\u8cc7\u6599\u7d50\u69cb<\/h2>\n<p><span style=\"color: #0000ff;\">java \u958b\u767c\u4e0a\u6211\u5011\u5e38\u5e38\u8b93\u7269\u4ef6\u7684\u8b8a\u6578\u4fdd\u6301 private \uff0c\u907f\u514d\u5176\u4ed6\u958b\u767c\u8005\u7a81\u767c\u5947\u60f3\u7684\u60f3\u8981\u6539\u52d5\u5176\u6578\u503c\u5c0e\u81f4\u72c0\u6cc1\u5927\u4e82<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u4f46\u70ba\u4f55\u9084\u662f\u6709\u90a3\u67d0\u591a\u5de5\u7a0b\u5e2b\u6703\u52a0\u4e0a setter and getter\uff0c\u641e\u5f97\u50cf\u662f public \u4e00\u6a23\uff0c\u5927\u5bb6\u60f3\u6539\u5c31\u6539<\/span><br \/>\n\uff08p.105\uff09<br \/>\n\u5176\u5be6\u5c31\u662f\u8cc7\u6599\u62bd\u8c61\u5316\uff0c\u6211\u63d0\u4f9b\u4f60\u7684\u8b80\u53d6\u8cc7\u6599\u7684\u76ee\u7684\u8981\u6c42\uff0c\u4f46\u662f\u624b\u6bb5\u7531\u6211\u63a7\u5236\uff0c\u91cdsetter and getter \u4f86\u770b<br \/>\n\u9019\u6a23\u7684\u6548\u679c\u4e26\u4e0d\u660e\u986f\uff0c\u4f46\u540c\u6a23\u662f\u4e0d\u544a\u8a34\u4f60\u88e1\u9762\u8a73\u7d30\u600e\u67d0\u904b\u4f5c\u7684<\/p>\n<h3>6.1 \u7269\u4ef6\u8207\u8cc7\u6599\u7684\u53cd\u5c0d\u7a31\u6027<\/h3>\n<p><span style=\"color: #0000ff;\">\u9996\u5148\u5148\u5b9a\u7fa9\u597d\u7269\u4ef6\u8207\u8cc7\u6599<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u7269\u4ef6\u5c07\u4ed6\u5011\u7684\u8cc7\u6599\u518d\u62bd\u8c61\u5c64\u4e4b\u5f8c\u96b1\u85cf\u8d77\u4f86\uff0c\u7136\u5f8c\u5c07\u64cd\u4f5c\u9019\u4e9b\u8cc7\u6599\u7684\u51fd\u5f0f\u66b4\u9732\u5728\u5916<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u8cc7\u6599\u5247\u5c07\u8cc7\u6599\u66b4\u9732\u5728\u5916\uff0c\u800c\u4e14\u4e5f\u6c92\u63d0\u4f9b\u6709\u610f\u7fa9\u7684\u51fd\u5f0f<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u6ce8\u610f\u9019\u5169\u500b\u5b9a\u7fa9\uff0c\u9019\u662f\u5c0d\u7acb\u4e14\u4e5f\u4e92\u88dc<\/span><br \/>\n\uff08p.107\uff09<br \/>\n\u770b\u500b\u4f8b\u5b50\uff1a<\/p>\n<pre>public class Square {\r\n    public Point topLeft;\r\n    public double side;\r\n}\r\npublic class Rectangle {\r\n    public Point topLeft;\r\n    public double height;\r\n    public double width;\r\n}\r\npublic class Circle {\r\n    public Point center;\r\n    public double radius;\r\n}\r\n\r\npublic class Geometry {\r\n    public final double PI = 3.14159;\r\n    \r\n    public double area(Object Shape) throws NoSuchShapeException {\r\n        if (shape instanceof Square) {\r\n            Square s = (Square) shape;\r\n            return s.side * s.side;\r\n        } else if (shape instanceof Rectangle) {\r\n            Rectangle r = (Rectangle) shape;\r\n            return r.height * r.width\r\n        } else if (shape instanceof Circle) {\r\n            Circle c = (Circle) shape;\r\n            return PI * c.radius * c.radius;\r\n        }\r\n        throw new NoSuchShapeException();\r\n    }\r\n}\r\n\r\n<\/pre>\n<p>\u8001\u5be6\u8aaa\u9019\u6a23\u7684\u7a0b\u5f0f\uff0c\u5fe0\u5be6\u7684\u7269\u4ef6\u5c0e\u5411\u7a0b\u5f0f\u8a2d\u8a08\u5e2b\u6703\u89ba\u5f97\u5f88\u8a6d\u7570\uff08\u6211\uff09\uff0c\u9019\u6839\u672c\u5c31\u662f procedural function<\/p>\n<p>\u6240\u4ee5\u63db\u500b\u65b9\u5f0f\u8a66\u8a66\u770b\uff08\u7269\u4ef6\u7248\uff09<\/p>\n<pre>interface Shape {\r\n   public double area();\r\n}\r\n\r\npublic class Square implement Shape {\r\n   private Point topLeft;\r\n   private double side;\r\n   public double area() {\r\n       return side * side;\r\n   }\r\n}\r\n\/\/....other class implement Shape\r\n\r\n<\/pre>\n<p><span style=\"color: #0000ff;\">\u5f9e\u4e0a\u9762\u5169\u500b\u4f8b\u5b50\u53ef\u4ee5\u770b\u51fa<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u5982\u679c\u8981\u52a0\u5165\u4e00\u500b\u65b0\u7684\u5716\u5f62\u985e\u5225\u6642\uff0c\u6703\u767c\u751f\u5565\u4e8b\uff1f<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u7b2c\u4e00\u6bb5\u7a0b\u5f0f\u78bc\uff0c\u6211\u5fc5\u9808\u8981\u4fee\u6539Geometry \u5167\u7684\u6240\u6709\u7684\u76f8\u95dc\u51fd\u5f0f\u624d\u80fd\u8655\u7406\u9019\u4ef6\u4e8b\u60c5<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u4f46\u662f\u63a1\u7528\u7b2c\u4e8c\u6bb5\u7a0b\u5f0f\u78bc\u7684\u8a71\uff0c\u5247\u6839\u672c\u4e0d\u9700\u8981Geometry \u9019\u500b\u985e\u5225<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u65b0\u589e\u4efb\u4f55\u985e\u5225\u90fd\u4e0d\u6703\u5f71\u97ff\u5230\u73fe\u6709\u7684\u51fd\u5f0f\u3002<\/span><\/p>\n<p><span style=\"color: #0000ff;\">\u90a3\u5982\u679c\u8981\u52a0\u5165\u4e00\u500b\u65b0\u7684\u51fd\u5f0f\u50cf\u662f perimeter() \u7684\u8a71\uff0c\u6703\u767c\u751f\u5565\u4e8b\uff1f<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u7b2c\u4e8c\u6bb5\u7a0b\u5f0f\u78bc\u7684\u6240\u6709 Shape \u7269\u4ef6\u90fd\u5fc5\u9808\u8ddf\u8005\u4fee\u6539\uff0c<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u4f46\u7b2c\u4e00\u6bb5\u7a0b\u5f0f\u78bc\u537b\u53ea\u8981\u4fee\u6539 Geometry \u985e\u5225\uff0c\u589e\u52a0\u4e00\u500b\u51fd\u5f0f\u5373\u53ef<\/span><br \/>\n\uff08p.108\uff09<\/p>\n<p>\u7531\u6b64\u53ef\u4ee5\u770b\u51fa\u9019\u5169\u7a2e\u8a2d\u8a08\u7684\u5c0d\u7acb\u4ee5\u53ca\u4e92\u88dc\u9762<br \/>\n\u518d\u6b21\u63a8\u5c0e\u51fa\u4f86\uff1a<br \/>\n<span style=\"color: #ff0000;\">\u300e\u7d50\u69cb\u5316\u7a0b\u5f0f\u78bc\u5bb9\u6613\u6dfb\u52a0\u65b0\u7684\u51fd\u5f0f\uff0c\u800c\u4e0d\u9700\u8981\u8b8a\u52d5\u5df2\u6709\u7684\u8cc7\u6599\u7d50\u69cb<\/span><br \/>\n<span style=\"color: #ff0000;\"> \u800c\u7269\u4ef6\u5c0e\u5411\u7684\u7a0b\u5f0f\u78bc\uff0c\u5bb9\u6613\u6dfb\u52a0\u65b0\u7684\u985e\u5225\uff0c\u800c\u4e0d\u7528\u8b8a\u52d5\u5df2\u6709\u7684\u51fd\u5f0f\u300f<\/span><br \/>\n\u53cd\u904e\u4f86\u8aaa\uff1a<br \/>\n<span style=\"color: #ff0000;\">\u300e\u7d50\u69cb\u5316\u7a0b\u5f0f\u78bc\u96e3\u4ee5\u6dfb\u52a0\u65b0\u7684\u8cc7\u6599\u7d50\u69cb\uff0c\u56e0\u70ba\u5fc5\u9808\u6539\u8b8a\u6240\u6709\u7684\u51fd\u5f0f<\/span><br \/>\n<span style=\"color: #ff0000;\"> \u7269\u4ef6\u5c0e\u5411\u7a0b\u5f0f\u78bc\u96e3\u4ee5\u6dfb\u52a0\u65b0\u7684\u51fd\u5f0f\uff0c\u56e0\u70ba\u5fc5\u9808\u6539\u8b8a\u6240\u6709\u7684\u985e\u5225\u300f<\/span><br \/>\n\uff08p.109\uff09<\/p>\n<p>\u672c\u4eba\u5118\u7ba1\u8eab\u70ba\u7269\u4ef6\u5c0e\u5411\u6d3e\u7684\u4e00\u4efd\u5b50\uff0c\u7576\u7136\u4e5f\u77e5\u9053\u5168\u90e8\u90fd\u662f\u7269\u4ef6\uff0c\u57fa\u672c\u4e0a\u662f\u500b\u795e\u8a71<br \/>\n\u6240\u4ee5\u5728\u9069\u5408\u7684\u6642\u5019\uff0c\u8981\u61c2\u5f97\u7528\u7d50\u69cb\u5316\u7684\u7a0b\u5f0f\uff08\u9700\u8981\u5e38\u5e38\u589e\u52a0\u6e1b\u5c11\u51fd\u5f0f\u7684\u60c5\u6cc1\uff09\uff0c\u5e6b\u52a9\u958b\u767c<\/p>\n<p>\u6240\u6709\u7684\u8a9e\u6cd5\u90fd\u662f\u5de5\u5177\uff0c\u6311\u6700\u9069\u5408\u7684\u5c31\u5c0d\u4e86<\/p>\n<h3>6.2 Data Transfer Object<\/h3>\n<p><span style=\"color: #0000ff;\">\u9019\u7a2e\u7269\u4ef6\u975e\u5e38\u5e38\u898b\uff0c\u57fa\u672c\u4e0a\u5c31\u662f\u8cc7\u6599\u5eab\u7684\u539f\u59cb\u8cc7\u6599 \u8f49\u6210 \u61c9\u7528\u7684\u7a0b\u5f0f\u5167\u7684\u7269\u4ef6<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u4f8b\u5982\uff1a greendao , json to object , gson \u9019\u985e\u7684\u95dc\u9375\u5b57<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u4fd7\u7a31bean<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u9019\u5176\u5be6\u5f88\u591a\u8cc7\u6599\u5167\u5bb9\u90fd\u53ef\u4ee5\u7528\u516c\u958b\u8b8a\u6578\uff0c\u4f46\u662f\u9084\u662f\u7fd2\u6163\u5beb\u6210setter and getter<\/span><br \/>\n<span style=\"color: #0000ff;\"> \u5176\u5be6\u5c31\u662f\u4e00\u7a2e\u50cf\u7269\u4ef6\u5c0e\u5411\u958b\u767c\u8005\u7684\u59a5\u5354<\/span><br \/>\n\uff08p.113\uff09<\/p>\n<p>\u8b80\u5230\u9019\u6bb5\u6642\uff0c\u7a81\u7136\u60f3\u5230\u4e4b\u524d\u8ddf\u8001\u5927\u5728\u8a0e\u8ad6\uff08\u611f\u89ba\u8ddf\u9019\u7ae0\u7bc0\u6c92\u5565\u95dc\u4fc2\uff09<br \/>\nandroid \u63d0\u4f9b\u5916\u90e8 api access content provider \u7684\u65b9\u6cd5\uff0c\u7528\u54ea\u7a2e\u6bd4\u8f03\u597d\uff1f<br \/>\n\u672c\u4eba\u89ba\u5f97 \u5c31\u8d70 content provider \u7684\u73a9\u6cd5\u52a0\u6587\u4ef6\uff0c\u63d0\u4f9b URI \u7136\u5f8c\u7528android \u539f\u751f\u7684 sqlite crud \u64cd\u4f5c<br \/>\n\u4e3b\u8981\u5c31\u662f\u4fdd\u6301\u8cc7\u6599\u7684\u5f48\u6027\u64cd\u4f5c\uff0c\u539f\u751f\u7684\u73a9\u6cd5\u5230\u54ea\u90fd\u4e0d\u6703\u6709\u932f\uff0c\u9019\u6a23\u53ef\u4ee5\u4fdd\u6301\u76ee\u524d\u7684\u7a0b\u5f0f\u78bc\uff0c\u4ee5\u6700\u5c0f\u7684\u4fee\u6539\u5e45\u5ea6<br \/>\n\u5c31\u53ef\u4ee5\u5b8c\u6210\u9019\u9805\u4efb\u52d9<br \/>\n\u8001\u5927\u89ba\u5f97 \u51fa\u5c08\u9580\u7684 lib \u628a\u6240\u6709\u7684crud\u64cd\u4f5c\u90fd\u898f\u7bc4\u8d77\u4f86\uff0c\u63d0\u4f9b example , \u8981\u6c42\u5b58\u53d6\u8005\u9020\u898f\u5247\u8d70<br \/>\n\u6709\u9ede\u5fd8\u4e86\u70ba\u4f55\uff0c\u4f46\u4e3b\u8981\u662f\u5229\u7528\u51fd\u5f0f\u7684\u64cd\u4f5c\uff0c\u8b93\u7b2c\u4e09\u65b9\u5fc5\u9808\u8a8d\u771f\u7684\u770b\u61c2\u624d\u80fd\u53bb\u64cd\u4f5c\u8cc7\u6599\u5eab<br \/>\n\u78ba\u4fdd\u5b89\u5168\uff0c\u4e26\u4fdd\u6301\u7a0b\u5f0f\u7684\u62bd\u8c61\u5316\uff0c\u4ee5\u5f8c\u96a8\u4fbf\u6539\u90fd\u53ef\u4ee5<\/p>\n<p>\u4e0d\u77e5\u9053\u500b\u4f4d\u770b\u5b98\u89ba\u5f97\u512a\u7f3a\u9ede\u662f\u5565\uff0c\u6216\u662f\u53ef\u4ee5\u88dc\u5145\u6c92\u6ce8\u610f\u5230\u7684\u9ede\uff0c\u6b61\u8fce\u8a0e\u8ad6<\/p>\n<h2>\u7b2c\u4e03\u7ae0 \u932f\u8aa4\u8655\u7406<\/h2>\n<p><span style=\"color: #0000ff;\">\u5b9a\u7fa9\u6700\u5c0f\u7684 handle scope \u548c\u6b63\u5e38\u7684\u7a0b\u5f0f\u6d41\u7a0b<\/span><\/p>\n<h3>7.1 try\/catch \u6700\u597d\u80fd\u5b9a\u7fa9\u5728\u6700\u7cbe\u6e96\u7684\u7bc4\u570d\uff1a<\/h3>\n<p><span style=\"color: #0000ff;\">\u4e00\u822c\u60c5\u6cc1\u4e0b\uff0c\u4e0d\u5c11\u4eba\u6703\u8caa\u5716\u65b9\u4fbf\uff0c\u6216\u53ea\u662f\u60f3\u907f\u958b\u7de8\u8b6f\u5668\u8df3\u51fa\u7684\u932f\u8aa4\uff0c\u9032\u800c\u628a\u4e00\u5927\u6bb5\u7a0b\u5f0f\u78bc\u7528 try\/catch \u5305\u8d77\u4f86\uff0c\u66f4\u751a\u8005\u53ea\u7528 Exception \u9019\u500b\u5de8\u5927\u7684\u932f\u8aa4\u76ee\u6a19\uff0c\u4f46\u9019\u6a23\u4ee5\u5f8c\u5fc5\u5b9a\u4ed8\u51fa\u4ee3\u50f9\uff0c\u6700\u4e3b\u8981\u7684\u5c31\u662f\u7121\u6cd5\u5728\u932f\u8aa4\u6642\uff0c\u63d0\u4f9b\u8db3\u5920\u7cbe\u78ba\u7684 error message\uff0e<\/span><\/p>\n<h3>7.2 \u6b63\u5e38\u7684\u7a0b\u5f0f\u6d41\u7a0b<\/h3>\n<p><span style=\"color: #0000ff;\">try\/catch \u7684 catch \u53ea\u53bb\u8655\u7406\u932f\u8aa4\u7684\u56de\u5fa9\uff0c\u78ba\u4fdd\u7a0b\u5f0f\u4e0d\u6703\u5361\u5728\u9019\u88e1\uff0c\u4f46\u662f\u4e0d\u8981\u628a\u5546\u696d\u908f\u8f2f\u5750\u5728 catch \u8655\u7406\uff0c\u4e5f\u5c31\u662f\u628a\u932f\u8aa4\u767c\u751f\u60c5\u6cc1\u7d66\u5e38\u614b\u5316\uff0c\u9019\u6703\u9020\u6210\u5f8c\u7e8c\u5176\u4ed6\u958b\u767c\u8005\uff0c\u7121\u6cd5\u5340\u5206\u5546\u696d\u908f\u8f2f\u548c\u932f\u8aa4\u8655\u7406\u7684\u5dee\u7570\uff0c\u4e5f\u5c31\u662f\u4e0d\u597d\u8b80\uff0c\u5149\u662f\u9019\u6a23\u5c31\u9055\u53cd\u4e86 clean code.<\/span><\/p>\n<h3>7.3 \u4e0d\u8981\u56de\u50b3 null<\/h3>\n<p><span style=\"color: #0000ff;\">\u300e\u8bb8\u591a\u8bed\u8a00\uff08C\uff0cC++\uff0cJava\uff0cC#\uff0c\u2026\u2026\uff09\u7684\u7c7b\u578b\u7cfb\u7edf\u5bf9\u4e8enull\u7684\u5904\u7406\uff0c\u5176\u5b9e\u662f\u5b8c\u5168\u9519\u8bef\u7684\u3002\u8fd9\u4e2a\u9519\u8bef\u6e90\u81ea\u4e8eTony Hoare\u6700\u65e9\u7684\u8bbe\u8ba1\uff0cHoare\u628a\u8fd9\u4e2a\u9519\u8bef\u79f0\u4e3a\u81ea\u5df1\u7684\u201cbillion dollar mistake\u201d\uff0c\u56e0\u4e3a\u7531\u4e8e\u5b83\u6240\u4ea7\u751f\u7684\u8d22\u4ea7\u548c\u4eba\u529b\u635f\u5931\uff0c\u8fdc\u8fdc\u8d85\u8fc7\u5341\u4ebf\u7f8e\u5143\u3002\u300f<\/span><\/p>\n<p><span style=\"color: #0000ff;\">\u6709\u4eba\u56de\u50b3 null \u90a3\u5c31\u4ee3\u8868\u6709\u4eba\u8981\u8655\u7406 null<\/span> \uff0c \u5f88\u597d\u9019\u6642\u5019\u500b\u4eba\u78ba\u8a8d\u4e00\u4e0b\u624b\u4e0a\u5c08\u6848\u7684 LPageLayout.java \uff0c\u5927\u6982\u7e3d\u5171\u5beb\u4e86\u7d04\uff14\uff10\u500b null \u6aa2\u67e5\uff0c\u9019\u5b8c\u5168\u5c31\u662f\u7d66\u81ea\u5df1\u627e\u9ebb\u7169\u7684\u884c\u70ba\uff0c\u9019\u6642\u5019\u6709\u4eba\u53ef\u80fd\u8a8d\u70ba\u53ef\u4ee5\u7528 NullPointerException \u4f86\u7701\u4e0b\u5927\u91cf\u7684 null check , \u4f46\u9019\u6642\u5019\u548c\u7b2c\u4e00\u9805\u7684\u300etry\/catch \u6700\u597d\u80fd\u5b9a\u7fa9\u5728\u6700\u7cbe\u6e96\u7684\u7bc4\u570d\uff1a\u300f\u5b8c\u5168\u885d\u7a81\uff0c\u5982\u679c\u7bc4\u570d\u5927\uff0c\u78ba\u5be6\u53ef\u4ee5\u7701\u4e0b\u5927\u91cf\u7684 null check \uff0c \u4f46\u662f\u7b2c\u4e00\u9805\u7684\u9ebb\u7169\u4e5f\u6703\u8ddf\u8005\u7522\u751f\u3002<br \/>\n\u56e0\u6b64\u6700\u597d\u7684\u65b9\u6cd5\u5c31\u662f\uff1a<span style=\"color: #ff0000;\"> \u4e0d\u8981\u56de\u50b3 null<\/span><br \/>\n\u6700\u5e38\u51fa\u73fe\u9019\u7a2e\u60c5\u6cc1\u5c31\u662f\uff0cList \u7684 null check \uff0c<\/p>\n<pre>List personalList = loader.getPersionalData();\r\nif (personalList != null) {\r\n    for (int i = 0; i &lt; personalList.size() ; i ++ ) {\r\n        xxxxx;\r\n        \/\/ \u5982\u679c\u9019\u6642\u5019\u727d\u626f\u5230\u591a\u57f7\u884c\u7dd2\u90a3\u5c31\u66f4\u523a\u6fc0\u4e86\r\n    }\r\n}\r\n<\/pre>\n<p>\u56e0\u6b64\u9019\u7a2e\u60c5\u6cc1\u4e0b\uff0c\u6211\u5011\u5b8c\u5168\u5efa\u8b70 loader.getPersionalData() \u56de\u50b3\u4e00\u500b list size is 0 \u7684 empty list\uff0c\u53ef\u4ee5\u7528<\/p>\n<pre>Collections.emptyList(); \r\n<\/pre>\n<p>\u4f86\u7522\u751f\u4e00\u500b\u7a7a list<\/p>\n<h3>7.4 \u4e0d\u8981\u50b3\u905e null<\/h3>\n<p><span style=\"color: #0000ff;\">\u6bd4\u56de\u50b3 null \u9084\u8981\u7cdf\u7cd5\u7684\u5c31\u662f\u50b3\u905e null \u53c3\u6578\u5230\u51fd\u5f0f\u88e1\uff0c\u5927\u90e8\u5206\u51fd\u5f0f\u7684\u53c3\u6578\u8655\u7406\u90fd\u4e0d\u6703\u9810\u60f3\u5230\u8f38\u5165\u53c3\u6578\u662f null \u7684\u60c5\u6cc1<\/span>\uff08\u57fa\u672c\u578b\u5225\u60f3\u5230\uff10\u7684\u60c5\u6cc1\u53ef\u80fd\u9084\u6709\uff09\uff0c\u5927\u90e8\u5206\u5c31\u76f4\u63a5\u7206\u500b NullPointerException \u7d66\u4f60\uff0c\u9019\u9020\u6210\u8981\u78bc\u662f\u4f60\u505a null check \uff0c\u4e0d\u7136\u5c31\u662f\u51fd\u5f0f\u7279\u5225\u5c0d\u53c3\u6578\u505a null check \uff08\u5efa\u8b70\u5229\u7528 @NonNull\uff09\uff0c\u7136\u5f8c\u7206 InvalidArgumentException\uff0c\u6211\u60f3\u9019\u5287\u60c5\u6c92\u6709\u597d\u592a\u591a\uff0c\u4e00\u6a23\u641e\u6b7b\u5927\u5bb6.<br \/>\n\u56e0\u6b64\u540c\u6a23\u6700\u597d\u7684\u65b9\u6cd5\u5c31\u662f <span style=\"color: #ff0000;\">\u4e0d\u8981\u50b3\u905e null<\/span><\/p>\n<p>&#8212;&#8211;\u7b2c\u4e00\u7bc0\u5148\u5230\u9019\u908a\uff0d\uff0d\uff0d\uff0d<\/p>\n<p>Clean code: \u7121\u6687\u7684\u7a0b\u5f0f\u78bc\u7684\u7b2c\u4e00\u6bb5\u5fc3\u5f97\u5148\u5beb\u5230\u9019\u88e1<br \/>\n\u7e3d\u5171\u6709\uff11\uff17\u7ae0\uff0c\u7e7c\u7e8c\u6574\u7406<\/p>\n<p>ps.\u539f\u672c\u4e0b\u4e00\u7ae0\u4ee5\u70ba\u6703\u5beb\u5f88\u9577\u7684<\/p>\n<p>\u5982\u679c\u6709\u4efb\u4f55\u9055\u53cd\u8457\u4f5c\u6b0a\u7684\u60c5\u4e8b\u767c\u751f\uff0c\u8acb\u4e3b\u52d5\u544a\u77e5\uff0c\u5c0f\u5f1f\u6703\u5feb\u901f\u4e0b\u67b6<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u300e\u552f\u4e00\u6709\u6548\u7684\u7684\u300e\u7a0b\u5f0f\u54c1\u8cea\u300f\u5ea6\u91cf\u55ae\u4f4d\uff1a \u6bcf\u5206\u9418\u7f75\u9ad2\u8a71\u7684\u6b21\u6578(wtf\/minutes)\u300f\u7248\u6b0a\u7db2\u5740\u9644\u4e0a<br \/>\n\u9019\u53e5\u8a71\u8b93\u6211\u60f3\u5230\u540c\u4e8b\u6539\u5176\u4ed6\u90e8\u9580\u7a0b\u5f0f\u78bc\u6642\u7684\u72c0\u6cc1\uff0c\u6211\u60f3\u4ee5\u6b64\u4f5c\u70ba\u5f15\u8a00\uff0c\u5df2\u7d93\u76f8\u7576\u8db3\u5920\u7684\u8868\u793a\u51fa \u5beb\u51faclean code \u7684\u91cd\u8981\u6027<br \/>\n\uff08\u5e8f\uff09<\/p>\n<p>\u8a8d\u771f\u4e00\u9ede\u7684\u8a71\u5c31\u662f\uff1a<br \/>\n\u300e\u4f60\u6709\u5169\u500b\u539f\u56e0\u4f86\u8b80\u9019\u672c\u66f8\uff1a\u9996\u5148\u4f60\u662f\u500b\u7a0b\u5f0f\u8a2d\u8a08\u5e2b\uff0c\u63a5\u8005\uff0c\u4f60\u60f3\u6210\u70ba\u4e00\u500b\u66f4\u597d\u7684\u8a2d\u8a08\u5e2b\u300f<br \/>\n\u6211\u81ea\u5df1\u52a0\u4e0a\u53bb\u7684\uff1a\u300e\u525b\u597d\uff0c\u597d\u7684\u8a2d\u8a08\u5e2b\u85aa\u6c34\u597d\u50cf\u9084\u80fd\u770b\u300f<\/p>\n","protected":false},"author":1,"featured_media":572,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,25,28],"tags":[31,29,30,54],"_links":{"self":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/98"}],"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=98"}],"version-history":[{"count":2,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/98\/revisions"}],"predecessor-version":[{"id":573,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/98\/revisions\/573"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/media\/572"}],"wp:attachment":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}