Srping boot中对象解耦一例

Srping Boot中AOP是解耦的一种方式,如果再加上面向对象的一些手段,那么在解耦方面将收到更好的效果,废话不提,直接上代码:

public abstract class aaa {
    public abstract String a();
    public String x()
    {
        return this.a();
    }
}
@Component
public class bbb extends aaa{
    @Override
    public String a()
    {
        return "this is b class.";
    }
}

在调用时:

@Autowired
private aaa x;

 public String index() {
String m = x.x();
}

通过监控m,发现m已经有值。

 

posted @ 2019-10-10 14:45  Shapley  阅读(115)  评论(0编辑  收藏  举报