Search code examples
architecturedomain-driven-designurl-rewritinglegacy

DDD, Anti Corruption layer, how-to?


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.


Solution

  • 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.

    EmployeeAccessService

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

    EmployeeAccessAdapter

    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)