Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Business Fa�ade Logic in distributed n-tier applications

0.00/5 (No votes)
9 Aug 2004 1  
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

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 :

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

The CreateFacade is implemented as follows

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here