带有Spring控制器的业务代表模式

时间:2015-10-20 14:00:20

标签: design-patterns

我正在使用Spring,其中我的服务实现被注入到Controller类中,这里是否与使用业务委托模式相关,因为服务接口和它们的注入已经提供了一定程度的解耦,我可以在其中修改服务实施

如果是,那么它应该是具有服务接口关系的一对一委托 或者我应该为所有服务创建共同委托。

示例

public class MyUIController扩展了BaseController {

private MyService1 myService1;
private MyService2 myService2;

...

@Autowired
public MyUIController (MyService1 myService1, MyService2 myService2...) {
    super();
    this.myService1= myService1;
    this.myService2= myService2;
}

1 个答案:

答案 0 :(得分:1)

使用委托模式在早期的EJB 2中更为普遍。但是,随着Spring和依赖注入的出现,Business Delegate层或多或少地失去了它的意义。

如果您确实使用了业务委托,那么您最有可能最终拥有一个委托层,它只是一个传递层,即委托层的所有方法都将是您的服务方法的精确副本。这是不必要的。您不需要委托层。

相关问题