views:

792

answers:

1

Okay, I have done a bit of searching online and found this thread, but it still does not quite clear it up for me.

What exactly is the difference between a Front Controller Pattern and a Façade pattern?

As I understand it so far: A Façade pattern does not contain any business Logic, but merely centralizes access to multiple objects.

A Front Controller does the same thing, but may contain business logic to facilitate the decision logic of what is called based on the input data and the like.

To make sense of this, does the following simplistic pseudo code snippet mean that drawLine is a Façade to simplify converting the coordinates to points and then implementing the draw method that actually does the work?

    private void drawLine(Int32 StartX, Int32 StartY, Int32 EndX, Int32 EndY)
    {
        Point Start = new Point(StartX, StartY);
        Point End = new Point(EndX, EndY);

        Draw(Start, End);
    }

Can a Façade call into lower layers of your application or is it really just to centralise access to many components on the same layer?

As I understand it, the front controller coordinates the complete function call process.

Example: A Front controller would examine the data, and then decide what action to take. Then it would compile the data for each subsequent call to lower level classes, until it arrives at a suitable response that can be provided to the calling system.

I think my understanding of the Façade pattern is wrong or just too simplistic. Please correct me if I'm wrong.

If my understanding of this is correct, would it then not make more sense to change the Application Façade, into a Front Controller in the Microsoft Application Architecture Guide 2.0? I'm specifically looking at the Service Architecture in chapter 18. (I have the Beta 2 version though)

Update: Thanks for a great response Rune. Why do you say it is not correct to change the Facade to a Front controller? I'm a big fan of the Front-controller because it keeps all lower level things a little more controlled. So although it may not make MORE sense, would it be completely wrong to do that? If yes: Why?

+2  A: 

The Front Controller pattern defines a single component that is responsible for processing application requests. Often used as a "bottleneck" to (for instance) channel requests through to consolidate standard behavior that needs to be performed each time.

See these links for short to the point explanations: http://java.sun.com/blueprints/patterns/FrontController.html http://martinfowler.com/eaaCatalog/frontController.html

A facade is on the other hand rather used to wrap other methods/services to provide a unified interface, hide complexity or reduce dependency on external systems (Exemplified in DDD's anti-corruption layer: http://www.goeleven.com/blog/entryDetail.aspx?entry=168), etc.

A facade is a thin wrapper that shouldn't contains any logic except the logic used to translate between the two systems. Front Controller has no such requirements.

See for instance: http://en.wikipedia.org/wiki/Facade_pattern

And to answer your questions concerning AppArchGuide: No, that's not correct.

Rune Sundling
Thanks for a great response. Why do you say it is not correct to change the Facade to a Front controller? I'm a big fan of the Front-controller because it keeps all lower level things a little more controlled. So although it may not make MORE sense, would it be completely wrong to do that? If yes: Why?
Gineer