2

Consider that the Facade has inside it lots of sub-components but it done not pass messages from one sub-component to the other but also has some business logic in it. Is it still Facade pattern?

Narek
  • 1,143

1 Answers1

3

I'm sure there's going to be a little debate here, but if we assume a Facade is a simplified interface into a larger body of code, then it can contain some business logic.

For example, say I have three calls I need to make, Method1, Method2, and Method3. They are each in disparate parts of the codebase, and there is not a mechanism for them to communicate with each other, but they need to act on a common object. At a minimum, I would use my Facade to pass the object into each method. What happens if I need to only pass them conditionally? Then I just add it into the facade class.

I would say that if you do the bulk of your business logic in the facade class, then you are probably not using the design pattern correctly. At its heart it is supposed to wrap other things, not do all the work itself, but some limited business logic should be fine.

Compare this design pattern to the Adapter pattern, which more literally translates from one system to what is expected by another, with zero business logic not involved in the translation.