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

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.

主站蜘蛛池模板: 南岸区| 巴里| 夏津县| 阳城县| 昌黎县| 万山特区| 剑河县| 宜兴市| 屏东县| 洪江市| 左权县| 多伦县| 江门市| 仁怀市| 衡阳市| 谷城县| 大冶市| 博罗县| 萨嘎县| 喀什市| 关岭| 宜兰县| 广汉市| 张家界市| 石狮市| 永平县| 南京市| 花垣县| 黑龙江省| 洛隆县| 宁德市| 墨竹工卡县| 曲松县| 潼关县| 和林格尔县| 涟源市| 泾川县| 永川市| 沧源| 保德县| 洪江市|