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

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

    You're thinking too granularly. A specific class should read the database- but you don't need a class whose sole job is to create a Person. That's just wasteful. A single database reader should be capable of creating any class that comes through the database- because that's it's job. To read from the database.

    There's no encapsulation problems with opening Person's properties so that DatabaseReader can access them, as Person is redundant if no class is capable of creating it. It's an inherent part of any classes responsibility to be creatable and destructible.

提交回复
热议问题