Search This Blog

2012-11-12

Separated Interface Design Pattern


When developing a system in many cases it is possible to identify dependencies among different layers whose responsibilities are well defined in the system.

Some examples of layer dependencies are:
  • Controller layer dependency and UI layer
  • Domain logic layer and persistence layer

One strategy to remove dependencies between layers is to use the separated interface design pattern. This pattern consists of defining an interface from the bottom layer that is going to be used by the top layer. See diagram below  to understand how it works for controller and UI layer:


The controllers in the example above only reference interface views and never know which view implementation they are actually working with.

This design pattern is recommended for a system when:
  • One layer (such as a controller) will be reused to be plugged into different versions of the other layer (such as HTML5 and native view layer implementations)
  • Layers are easier to be tested in isolation
  • It is not desired that one layer has API dependencies from the other layer

References: