41

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.

2 Answers 2

40

From the DDD book (Domain-Driven Design: Tackling Complexity in the Heart of Software) by Eric Evans:

The public interface of the ANTICORRUPTION LAYER usually appears as a set of SERVICES, although occasionally it can take the form of an ENTITY.

and a bit later

One way of organizing the design of the ANTICORRUPTION LAYER is as a combination of FACADES, ADAPTERS (both from Gamma et al. 1995), and translators, along with the communication and transport mechanisms usually needed to talk between systems.

So, you might find examples by looking at the suggested adapter pattern and facade pattern.

I'll try to paraphrase what Eric Evans said, your anti-corruption layer will appear as services to the outside of your layer. So outside of the anti-corruption layer the other layers will not know they are "speaking" with a anti-corruption layer. Inside of the layer you would use adapters and facades to wrap your legacy information sources.

More information about the anti-corruption layer:

5
  • Thanks. I will check those out right now. But i got a feeling already that it won't be enough. Aren't there any code examples? :) Commented May 26, 2009 at 7:07
  • c-sharpcorner.com/UploadFile/rmcochran/… this one is great to understand Adapter pattern :) Commented May 26, 2009 at 7:25
  • 3
    Links Building the often needed anti-corruption layer(joeydotnet.com/blog/archive/2007/09/10/…) and DDD - Anti corruption layer(goeleven.com/blog/entryDetail.aspx?entry=168 ) are broken Commented Sep 22, 2012 at 12:17
  • 1
    This is super old I realize but to answer the OP you're not going to find code samples for an ACL. Patterns are too high level and there are too many variables for a cookie-cutter recipe. My advice is if the ACL is needed just for the life of the migration and no longer then don't get fancy. It doesn't have to be pretty. Just write tests and make sure it works. Data integrity is key here not performance or beautifully refactored code.
    – James
    Commented Mar 13, 2019 at 18:44
  • only one of those 3 links at the end are opened Commented Mar 22, 2019 at 2:57
20

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)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.