Search code examples
javapackagefacade

Inside the package, I must use the Facade Pattern (or something similar)?


I'm using a Facade to access the methods and classes inside package, but and inside the package? I must access the methods of other class directly or by a facade or something similar?

Example: Package 1(Class Foo, Class Bar, Facade FooBar)

Outside Class -> FooBar --> Foo method

but inside:

Foo --> Bar or Foo --> FooBar --> BarFacade


Solution

  • A facade is a single interface which allows easy access to all the functionality going on behind the scenes. It is not the same thing as a requirement to pass internal functionality between components back out of the system (and back into it through the interface).

    Facades are control panels, they simplify and hide the internal components so external users don't get lost in the complexity of what is behind the interface. An interface with internal components that reaches back outside and manipulates itself through the interface would make a good art presentation, but would be a lousy Facade, as it would expose that which is it trying to hide.

    Outside -> Facade -> Inside.
    

    not

    Outside -> Facade -> Inside -> Facade -> Inside.
    

    or in your case

    OutSide -> FooBar -> Foo -> Bar
    

    would be just fine.