Should a parent class ever reference child classes?

后端 未结 4 751

Good morning,

I inherited some legacy code at work and it is using a rather unusual design pattern. The only reference I could find on the forums to a similar patter

4条回答
  •  感动是毒
    2021-01-14 18:17

    It is a good practise and called Factory Method.

    The benefit is that you return some concrete implementation but hide it via common interface or base class. Thus client isn't bothered by implementation details, but works with a most basic class.

提交回复
热议问题