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

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.

主站蜘蛛池模板: 永仁县| 惠州市| 扬中市| 集贤县| 汝南县| 吴忠市| 万荣县| 淮安市| 黔西县| 忻州市| 界首市| 沭阳县| 商城县| 仙居县| 集贤县| 子洲县| 堆龙德庆县| 南皮县| 武邑县| 商河县| 上高县| 新疆| 多伦县| 大埔县| 东乡县| 尚志市| 茂名市| 辉南县| 平和县| 黄大仙区| 海伦市| 六枝特区| 廊坊市| 永安市| 松滋市| 丹东市| 大城县| 平和县| 南雄市| 方正县| 军事|