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

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.

主站蜘蛛池模板: 敖汉旗| 新沂市| 高邮市| 余姚市| 辽宁省| 个旧市| 天峨县| 宁波市| 乌拉特前旗| 汶上县| 温宿县| 德格县| 南汇区| 紫阳县| 安龙县| 大冶市| 类乌齐县| 安庆市| 石渠县| 华池县| 贵定县| 论坛| 宜黄县| 通山县| 美姑县| 资阳市| 清镇市| 共和县| 精河县| 垣曲县| 商河县| 宜都市| 微山县| 时尚| 财经| 云龙县| 越西县| 东乡族自治县| 蒙自县| 郎溪县| 庄浪县|