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

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.

主站蜘蛛池模板: 石林| 昆山市| 偏关县| 三明市| 永新县| 怀集县| 贵阳市| 罗甸县| 綦江县| 确山县| 施甸县| 沙洋县| 乳山市| 宝清县| 金秀| 芒康县| 新安县| 轮台县| 玉树县| 仲巴县| 北票市| 米易县| 梨树县| 泽普县| 商河县| 甘洛县| 宁陕县| 灌云县| 岳阳市| 来宾市| 云林县| 巩义市| 黄石市| 咸阳市| 宜兴市| 乌拉特中旗| 双桥区| 民勤县| 静海县| 天气| 房产|