Click here to Skip to main content
15,886,578 members
Articles / Programming Languages / Visual Basic
Article

Business Façade Logic in distributed n-tier applications

Rate me:
Please Sign up or sign in to vote.
2.30/5 (12 votes)
9 Aug 2004CPOL3 min read 105.9K   562   50   9
Explains how to implement a Business Façade logic layer between the Presentation logic and the Business logic in an n-tier application

Introduction

If you are focused on implementing a distributed application architecture in .Net and if you are looking for an interface between the Presentation tier and the Business Logic tier, then the Business Façade classes would provide you with the interface you need, along with its advantages.

What's a Façade

Façade is a Design Pattern. It provides a unified interface to a set of interfaces in a subsystem. It defines a higher-level interface that makes the subsystem easier to use.

If the Façade is placed between the Business logic and the Client interface, it offers a single, simple interface to the Business logic subsystem.

Why do I have to use the Façade

The purpose of using the façade class is to eliminate the difficulties that the client would otherwise have in sending requests to a complex set of service objects. The client sends its requests to an instance of the façade class, which acts as an agent manipulating the requests as necessary and sending them on to the set of business classes.

At the cost of one class, the Façade makes it very easy for the Presentation Tier to access the methods of the Business Tier without having to navigate a bunch of potentially complex interfaces. The Façade class also promotes a weak coupling between the Business Rules Tier and the Presentation tier and hence lets you vary the components of the Business Rules without affecting the Presentation tier.

Façade Logic

The Façade layer used in the sample source has the following components
  • Factory Class - MyFactory
  • Façade Interface - IMyFacade
  • Façade Class - MyFacade

MyFactory

MyFactory is a Factory Class. This is another Design Pattern. Factory class lets a class defer instantiation to subclasses. It is an interface for creating objects of the Façade Class. The Factory class implements a method called CreateFacade which is solely responsible for instantiating objects of the IMyFacade interface class.

IMyFacade

The IMyFacade is the Façade Interface that defines the methods implemented in the Façade classes. IMyFacade delegates the requests to appropriate classes that implement the methods.

QJFacade

This class contains different subclasses:

  • UIFacade - used by component located on Web Server
  • WSFacade - used by Web Services
  • NRFacade - used through .Net Remoting

Each of these classes contain their own implementation of the methods that are defined in the interface IMyFacade. These methods make use of the Business Logic functionality. It is upto these classes to handle the interaction between the Business Logic.

Class Diagram

Implementation

VB.NET
Dim iFacade As IMyFacade  '   Facade Interface
Dim Factory As MyFactory  '   Factory Class 
'   Create a new factory class
Factory = New MyFactory()
'   Create a new Facade class. In this case we create a new instance of UIFacade
iFacade = Factory.CreateFacade(MyFactory.MyFType.UIF) '   Type UIF 
'   Call the required methods which inturn make use of the Business Logic methods
Dim strReturn As String
strReturn = iFacade.DoSomeLogic()

The Presentation layer creates an instance of the Factory class MyFactory.This instance is used to call the Factory method CreateFacade. CreateFacade requires a Enumerated type as a parameter which will decide the type of the Façade class to be instantiated.

The method calling the CreateFacade recieves an object of type specified in the parameter. This object is then used to call the relevant method in the Façade class.

For example :

VB.NET
iFacade = Factory.CreateFacade(UIF)
returns an instance of UIFacade.
VB.NET
iFacade = Factory.CreateFacade(WSF)
returns an instance of WSFacade
VB.NET
iFacade = Factory.CreateFacade(NRF)
returns an instance of NRFacade

The CreateFacade is implemented as follows

VB.NET
Public Function CreateFacade(ByVal nType As Integer) As Object

    '   Create an instance of the Façade classes based on the Type required.
    If (nType = MyFType.UIF) Then
        Return New MyFacade.UIFacade()

    ElseIf (nType = MyFType.WSF) Then
        Return New MyFacade.WSFacade()

    ElseIf (nType = MyFType.NRF) Then
        Return New MyFacade.NRFacade()
    End If

End Function

That's it

The source code contains a sample console application illustrating the use of the Façade Classes. The Façade logic can be used as an interface between your Presentation Tier and Business Logic giving you the following advantages

  • Provides you with a level of isolation between the Presentation Logic and the Business Logic. The Façade shields the Presentation Logic from the inner workings of the Business Logic.
  • Interfacing between many modules and classes is made more manageable. It makes the architecture more simpler.
  • Minimizes the communication and dependency between subsystems. Provides an amount of weak coupling between the Presentation Logic and the Business Logic

The Presentation Logic will now be only involved in presenting the UI. The Business Logic will only be involved in delivering the Business related logic. All the communication between the Presentation Layer and the Business Logic Layer will now be fully handled by the Business Façade, thus isolating the components of the application in terms of functionality.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalfacade architecture Pin
csp21-May-08 1:28
csp21-May-08 1:28 
GeneralClear, concise, and to the point Pin
dasypha9-Jun-07 7:39
dasypha9-Jun-07 7:39 
GeneralRe: Clear, concise, and to the point Pin
Tingu Abraham12-Jun-07 5:56
Tingu Abraham12-Jun-07 5:56 
Questionpresentation logic? Pin
Umer Khan12-Apr-07 21:58
Umer Khan12-Apr-07 21:58 
QuestionNice Article, I have a couple questions. Pin
Kevin Jensen23-Mar-07 4:01
Kevin Jensen23-Mar-07 4:01 
AnswerRe: Nice Article, I have a couple questions. Pin
Tingu Abraham23-Mar-07 7:10
Tingu Abraham23-Mar-07 7:10 
GeneralGood one!! Pin
Pasham28-Mar-06 19:18
Pasham28-Mar-06 19:18 
GeneralRe: Good one!! Pin
Tingu Abraham28-Mar-06 19:24
Tingu Abraham28-Mar-06 19:24 
Go ahead Sri
What is your question?
GeneralGood article Pin
b_raja4-Oct-05 3:28
b_raja4-Oct-05 3:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.