官术网_书友最值得收藏!

Implementing the Abstract factory design pattern in the Spring Framework

In the Spring Framework, the FactoryBean interface is based on the Abstract Factory design pattern. Spring provides a lot of implementation of this interface, such as ProxyFactoryBean, JndiFactoryBean, LocalSessionFactoryBean, LocalContainerEntityManagerFactoryBean, and so on. A FactoryBean is also useful to help Spring construct objects that it couldn't easily construct itself. Often this is used to construct complex objects that have many dependencies. It might also be used when the construction logic itself is highly volatile and depends on the configuration.

For example, in Spring Framework, one of the FactoryBean implementations is LocalSessionFactoryBean, which is used to get a reference of a bean that was associated with the hibernate configuration. It is a specific configuration concerning the data source. It should be applied before you get an object of SessionFactory. You can use the LocalSessionFactoryBean to apply the specific data source configuration in a consistent way. You may inject the result of a FactoryBean's getObject() method into any other property.

Let's create a sample implementation of the Abstract Factory design pattern.

主站蜘蛛池模板: 五大连池市| 九台市| 麦盖提县| 泰兴市| 巫山县| 商水县| 大石桥市| 馆陶县| 靖宇县| 金寨县| 昌乐县| 绥中县| 麻江县| 合水县| 三门峡市| 大丰市| 辽宁省| 顺平县| 吴川市| 翼城县| 巴青县| 鄢陵县| 东港市| 奈曼旗| 克拉玛依市| 东辽县| 枞阳县| 莲花县| 新民市| 鄯善县| 板桥市| 涡阳县| 浠水县| 沙湾县| 泰来县| 天等县| 共和县| 溧阳市| 武城县| 崇明县| 武山县|