Is a switch statement applicable in a factory method? c#

前端 未结 6 411
野趣味
野趣味 2020-12-29 09:45

I want to return an Interface and inside a switch statement I would like to set it. Is this a bad design?

private IResultEntity GetEntity(char? someType)
            


        
6条回答
  •  青春惊慌失措
    2020-12-29 10:34

    It's not bad, it's almost exactly the same as an example (Parameterized Factory Method) in the Gang of Four Bible itself.

    I used to think that switch statements are a code smell, they are not, they have their place in any OO language.

提交回复
热议问题