Constructor Injection - Do we inject factories as well?

前端 未结 2 1573
猫巷女王i
猫巷女王i 2021-02-15 07:12

After listening to the Clean Code Talks, I came to understand that we should use factories to compose objects. So, for example, if a House has a Door a

2条回答
  •  滥情空心
    2021-02-15 07:39

    If you inject too many factories that is a code smell called constructor over-injection that indicates your class is doing too much.

    Many containers provide a feature called auto-factories. That means they generate factories of type Funcautomatically if they know how to generate T.

    Castle Windsor has an advanced feature called Typed Factory facilities which generates implementations of a factory interface on-the-fly.

    There is also a port of typed factories for Unity in the TecX project.

提交回复
热议问题