Using the “Single Responsibility Principle” forces my containers to have public setters

前端 未结 4 1603
别那么骄傲
别那么骄傲 2021-02-08 23:56

I\'m trying hard to design following the SOLID principles. What I\'ve found is that when you use the \"Single Responsibility Principle\" (the S of SOLID) you usually have to spl

4条回答
  •  甜味超标
    2021-02-09 00:10

    Most data access strategies (ORM techniques) involve compromises of the kind you're describing. The least intrusive ones use reflection (or introspection, etc.) to populate your entities when they need to (when no public setters exist, for example).

    Having said that, if your entities are only data containers (as in the anemic domain model), the single responsibility principle shouldn't really concern you much, since your objects don't have complex logic that would be spoiled by (or interfere with) data access code.

提交回复
热议问题