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

前端 未结 4 1604
别那么骄傲
别那么骄傲 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:19

    Maybe I'm missing something, but why won't you write a constructor for Person class which accepts all it's properties? This way the PersonReader will be able to create a person without you opening the person's properties.

    Another option is to mark the setter of the person's properties as internal (And make the assembly internals visible to the assembly of the PersonReader, if it's in a different assembly). This will allow you to access the person properties, but will prevent anyone to change them outside of the assembly.

提交回复
热议问题