Facade

Problem

Assume a client package uses a provider package:

For example:

client = presentation tier
provider = business tier

client = business tier
provider = data tier

Assume the client package contains the following classes:

client.C1, client.C2, client.C3

Assume the provider package contains:

provider.P1, provider.P2, provider.P3, provider.P4, proviader.P5

In the worst case scenario, every client class depends on every provider class:

The coupling degree between the client package and the provider package is too high. The client knows too much about the structure of the provider package, making it difficult to modify the provider package.

Solution

Introduce a Facade class to the provider package. This is the only class that has public scope, the rest of the classes in the provider package have package scope. The facade receives all requests from the client package. The facade choreographs all major transactions with the provider package: