Search code examples
javaspringdesign-patternsfacade

Facade of services in Spring


I'm working on my first app in Spring and I have a design problem. I've created a few services that I'd like to use through a few facades (is it good idea?). I'd like to have structure like this

/services
  /facades
    /interfaces
      **facades**
    /implementations
      **sampleFacades**
  /interfaces
    **services**
  /implementations
    **sampleServices**

with package-private services (interfaces and implementations). Is it possible or I have to put all classes to one package?


Solution

  • The Facade Pattern is meant to create a simplified and dedicated access to more complicated code.

    Typically you would have an API created by someone else and you would then create your own custom API to consume the other.

    In this case you seem to be creating façades to Services in within the same Spring Applicaiton, which to me does not really make sense.

    Why create façades when you have control over the service definitions?

    If there is a need for a façade for your own service, perhaps they are not defined at the right level of granularity?

    Note that some of the complexity of the Services should be addressed by other patterns such as Data Access Objects coordinated by the Services.

    Regarding your question on putting all the classes in the same package, consider the Bounded Contexts of Domain Driven Design and organize your code around the domain instead of implementation details.