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

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.

主站蜘蛛池模板: 治多县| 安乡县| 康保县| 云和县| 北川| 武邑县| 盐亭县| 邹平县| 靖州| 京山县| 微山县| 吴江市| 花莲市| 红安县| 工布江达县| 内乡县| 灵武市| 海阳市| 明星| 寻乌县| 长寿区| 阜新| 吉安县| 莱西市| 津南区| 平遥县| 五河县| 九江县| 长岭县| 海安县| 通州区| 东丽区| 城固县| 伊吾县| 定安县| 雅安市| 衡山县| 清水河县| 土默特左旗| 东乡族自治县| 邯郸县|