DDD,反腐败层,如何做? [英] DDD, Anti Corruption layer, how-to?

查看:35
本文介绍了DDD,反腐败层,如何做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我们必须构建一个基于遗留应用程序的应用程序.旧应用程序的代码应该扔掉并重新编写,但正如往常一样 - 我们需要在它的基础上创建新的东西,而不是重新编写它.最近,我们决定走 DomainDrivenDesign 的道路.所以——反腐败层可以解决我们的问题.据我了解,这种方式应该可以逐步重写旧的应用程序.

At the moment, we have to build an application which is based on a legacy one. Code for that old application should be thrown away and rewritten, but as it usually goes - instead of rewriting it, we need to base something new on it. Recently, we decided to go the DomainDrivenDesign path. So -- anti corruption layer could be a solution for our problems. As far as I understand, this way it should be possible to gradually rewrite the old application.

但是——我找不到任何好的例子.我很感激任何信息.

But -- I can't find any good example. I would appreciate ANY information.

推荐答案

在我的特定实现中,EmployeeAccessService 由存储库调用.这真的是反腐败层的门面.它委托给EmployeeAccessAdapter.适配器从遗留模型中获取一个对象(它从 EmployeeAccessFacade 中获取),然后将其传递给 EmployeeAccessTranslator 以将对象从遗留模型转换为我的应用程序模型中的域对象.

In my particular implementation, EmployeeAccessService is called by a Repository. It's really a facade into the Anti-corruption layer. It delegates to the EmployeeAccessAdapter. The adapter fetches an object from the legacy model (which it gets from EmployeeAccessFacade),then passes it to the EmployeeAccessTranslator to transform the object from the legacy model to the domain object in my application's model.

员工访问服务

public Employee findEmployee(String empID){
    return adapter.findEmployee(empID);
}

员工访问适配器

public Employee findEmployee(String empID){
    EmployeeAccessContainer container = facade.findEmployeeAccess(empID);
    return translator.translate(container);
}

EmployeeAccessTranslator

public Employee translate(EmployeeAccessContainer container){
    Employee emp = null;
    if (container != null) {
        employee = new Employee();
        employee.setEmpID(idPrefix + container.getEmployeeDTO().getEmpID());
        ...(more complex mappings)

这篇关于DDD,反腐败层,如何做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆