Number of calls from Facade in Facade Pattern
We are having a "discussion" about what should be placed in the facade layer and how many calls the facade layer should make to the underlying layers.
In our project we have an Orchestration layer that coordinates calls to services and databases. We also have a business layer with business rules and calculations.
Our facade layer has a security check, logging a开发者_Go百科nd error handling.
Now the question: Should the facade have only a single call to the orchestration layer or is it Ok with multiple calls. If it is only a single call should these layers be merged into a single layer.
These are WCF services written in C#.
The number of calls inside of the Facade shouldn't matter as long as the call does one single operation (in the eyes of the caller) and does it completely.
Keep in mind that a single operation to the caller may include logging, running business rules, opening a connection to the database, writing to the database, and then finally closing and cleaning up the connection.
I support Justin's answer, to which I add only one consideration. If your orchestration layer does handle business layer too and if your facade ends up being a 1-to-1 map to orchestration tasks, then you could consider having orchestration to be your facade. But in this case you wouldn't be asking, so either your facade is simplifying the orchestration usage protocol, or orchestration and business layer are peers. In either case you need a facade that is distinct from orchestration module
If it is only a single call should these layers be merged into a single layer.
Are the Facade and Orchestration layers loosely-coupled? If so then my answer would be "no" don't merge. Just from a principles perspective I would think there is value in the loose-coupling, and that it should be preserved.
Should the facade have only a single call to the orchestration layer or is it Ok with multiple calls.
The moment it makes more than one call - what's the difference between what it's doing and what the Orchestration layer is doing. Think about their reason for living.
However, I'd allow a distinction between purely "business" calls and "cross-cutting" calls. By establishing the convention that only one "business" call is allowed to be "passed through" the Facade you keep a clean structure to the business services (there's never any confusion); but on the other hand your not technically constrained from making other cross cutting calls that augment system behavior and capability.
精彩评论