1

I usually see some people used facade like this.

public class FooFacade {
   Foo foo;

   public boolean isFunny(param1, param2) {
       IsFunnyInput isFunnyInput = new IsFunnyInput(param1, param2);
       return foo.isFunny(isFunnyInput);
   }
}

Is this a right approach? In my opinion, it is just adding one more class to the package. When you can also directly use Foo to do the same.

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142

2 Answers2

1

For me, it is an example of the decorator pattern and it makes sense only if Foo and FooFacade share the same interface.

interface Foo { boolean isFunny(p1, p2); }
class FooFacade implements Foo { ... } // FooDecorator, actually

In contrast, the Facade pattern is used to perform more complex interactions where a few different classes involved (and to hide this complexity).

The Wrapper pattern (aka Adapter) implies several interfaces.

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
0

I would normally use a Facade to hide the inner implementation details and classes used by for example another third-party library or some complex subsystem. If the IsFunnyInput-Class is from another library or one submodule the facade would help you to easily switch the library or change some implementation details as it is wrapped by a facade and all your code would use the facade. If you're just going to wrap your self written classes that simple into a facade without additional classes involved, i do not see any real benefit!

Here is a really good explanation of the Facade Design pattern

gmeiner.m
  • 747
  • 5
  • 19