Abstract factory pattern on top of IoC?

后端 未结 2 1157
猫巷女王i
猫巷女王i 2020-11-30 17:42

I have decided to use IoC principles on a bigger project. However, i would like to get something straight that\'s been bothering me for a long time. The conclusion that i ha

2条回答
  •  有刺的猬
    2020-11-30 17:57

    Well at the top most part of your application you will need a Bootstrap class that loads the IOC context. This context then will provide the actually instantiated objects and therefore acts as a factory.

    But this should only happen with very few objects and the user of your Bootstrap/Factory class should know as little about the underlying architecture as possible. For example if you configured a HTTP server object completely via IOC and you want to start it your Bootstrap class only needs to provide a getHttpServer() method. Then your programs main method only needs to call Bootstrap.getHttpServer().start() to get it running.

    The wiring of your other objects has already been done by the application context e.g. you configure Object A via IOC which is part of Object B so you configure Object B with the reference to Object A. None of them usually need to know neither about the container nor the factory.

提交回复
热议问题