技术开发 频道

SCA软件架构设计理念分析

    (2)Factory设计模式的深化和发展

    与插件式软件设计模式类似,Factory设计模式方面也有很大地发展和提高,为此仅用例子如SpringImplementationProviderFactory来说明Facory模式方面的设计理念和技巧。

    如图所示,左上角的部分也同样是插件式模式。在META-INF/services/目录下有文件名称为“org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint”,文件内容有用的仅一行是“org.apache.tuscany.sca.provider.DefaultProviderFactoryExtensionPoint”,就是这样把DefaultProviderFactoryExtensionPoint插入到DefaultExtensionPointRegistry插件板的,同样ProviderFactoryExtensionPoint为接口名称,DefaultProviderFactoryExtensionPoint为实现该接口的具体实现。

    在ProvideFactory接口中定义了Class<M> getModelType()方法,在SpringImplementationProvideFactory中实现为:

    public Class<SpringImplementation> getModelType()
    {
    return SpringImplementation.class;
    }

    其中的ModelType就对应于的model的值  ,即META-INF/services/目录下的是“org.apache.tuscany.sca.provide.ImplementationProviderFactory”文件下每行数据中的model属性的值(org.apache.tuscany.sca.implementation.spring.SpringImplementation)。

    在ImplementationProviderFactory<M extends Implementation>中定义了factory方法createImplementationProvider(…),在SpringImplementationProvideFactory中实现为:


    public ImplementationProvider createImplementationProvider
    (RuntimeComponent component,
    SpringImplementation implementation)
    { return new SpringImplementationProvider(component,
    implementation, proxyService, propertyFactory);
    }

0
相关文章