官术网_书友最值得收藏!

How it works...

If you have code that looks like the preceding one, you are in contravention of the SRP. The StarShip class is no longer responsible for just itself and things that have to do with star ships. It now has to fulfill the role of logging errors to the database too. You see the problem here is that the database-logging code does not belong in the catch clause of the SetMaximumTroopCapacity method. A better approach would be to create a separate DatabaseLogging class with methods to create connections and write exceptions to the appropriate log table. You will also find that you are going to have to write that logging code in multiple places (in every catch clause). If you are finding that you are repeating code (by copying and pasting from other areas), you probably need to put that code into a common class, and you have likely broken the SRP rule.

主站蜘蛛池模板: 桐庐县| 张掖市| 临武县| 马山县| 增城市| 岫岩| 五大连池市| 大同县| 天津市| 嵊州市| 巴林左旗| 盘锦市| 镇雄县| 灯塔市| 军事| 衡阳市| 石门县| 丘北县| 名山县| 新蔡县| 兴仁县| 乐山市| 桦南县| 陵水| 阳春市| 大丰市| 宜川县| 黄浦区| 武平县| 长顺县| 南安市| 沙河市| 洛隆县| 伊宁县| 海口市| 建水县| 秀山| 类乌齐县| 浮山县| 定西市| 陇南市|