1 / 14

Façade Pattern

Façade Pattern. Seung Ha. Façade?. Façade is generally one side of the exterior of a building, especially the front. Meaning “frontage” or “face”. In software architecture, façade defines high level interface to use subsystems. High-level Interface.

morse
Download Presentation

Façade Pattern

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Façade Pattern Seung Ha

  2. Façade? • Façade is generally one side of the exterior of a building, especially the front. • Meaning “frontage” or “face” • In software architecture, façade defines high level interface to use subsystems.

  3. High-level Interface Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use. client classes subsystem classes facade

  4. When Façade Pattern is used? • To provide simple interface to a complex subsystems. • To decouple the subsystem from clients and other systems. • To layer subsystems.

  5. Structure and Participants • Façade • The façade class interacts subsystem classes with the rest of the application. • Subsystem classes • Software library / API collection accessed through the façade class • Clients • The objects using the façade pattern to access resources from the subclasses Client1 Client2 facade DoSomething() Class1 Class3 Public void DoSomething() { Class1 book = new Class1(); Class2 customer = new Class2(); Class3 billing = new Class3(); book.CheckStock(); customer.GetShippingInformation(); billing.Process(book, customer); } Class2

  6. Consequences • Shields clients from subsystem components. • Reducing the number of objects that clients deal with and making the subsystem easier to use. • Layer a system and the dependencies between objects. • Eliminate complex or circular dependencies. This can be an important consequence when the client and the subsystem are implemented independently. • Reducing compilation dependencies – vital in large software systems

  7. Implementation • Reducing client-subsystem coupling: • The coupling between clients and the subsystem can be reduced even further by making Façade an abstract class with concrete subclasses for different implementation of a subsystem. • Public vs. private subsystem classes: • Public interface to a subsystem consists of classes that all clients can access (Façade class is part of the public interface.) • Private interface is just for subsystem extenders.

  8. Sample Code Client Web Page <Classes> • Data Access Layer vs. Business Layer • Data access subclasses defines how to access databases and meta data. • Business logic classes knows how to use data. • Façade – Data object • Common authentication interface • XML standardized data structure • Simple interface to access data Business Logic <Classes> Facade Data Object <Classes> Data Access Subclasses Database SQL Server Database Access

  9. Sample Code Client – ASP.NET page ... private void GetData(intproductID) { VirtualObjectModel.Framework.Login login = new VirtualObjectModel.Framework.Login( System.Configuration.ConfigurationSettings.AppSettings["LoginID"], System.Configuration.ConfigurationSettings.AppSettings["Password"], System.Configuration.ConfigurationSettings.AppSettings["Database"], System.Configuration.ConfigurationSettings.AppSettings["DatabaseServer"]); VOM.ObjectModel.Northwind.Productsobj = new VOM.ObjectModel.Northwind.Products(login.ConnectionString); obj.GetData(productID); SetData(obj); } ...

  10. Sample Code Business Object [Serializable()] public class Products { ... public virtual void GetData(intproductID) { try { XLMLDataTablexdt = new XLMLDataTable(_connectionString); xdt.DataSourceType = XLMLType.DataSourceType.SQLServer; xdt.CommandText = @"SELECT * FROM Northwind.dbo.[Products] WHERE ProductID = @ProductID"; xdt.XLMLParameterList.Add("@ProductID", VirtualObjectModel.Framework.XLMLType.DataType.INT).Value = productID; xdt.GetData(); foreach (XLMLDataRowxdr in xdt.XLMLDataRowList) { Products obj = this; xdr.SetAttribute(obj); }; } catch (System.Exception ex) { throw ex; } } ... }

  11. Sample Code Façade – Data Object public class XLMLDataTable:XLML { ... public void GetData() { try { if (this.ConnectionString != string.Empty || this.CommandText != string.Empty) { XLMLDataTablexlmlDataTable = new XLMLDataTable(); switch (this.DataSourceType) { case XLMLType.DataSourceType.SQLServer: xlmlDataTable = GetXLMLDataTable(MSSQLServerDataService.ExecuteReader(this.ConnectionString, this.CommandType, ... break; case XLMLType.DataSourceType.Access: xlmlDataTable = GetXLMLDataTable(GetDataTable(this.ConnectionString, this.CommandText)); break; default: break; } this.Description = xlmlDataTable.Description; this.ID = xlmlDataTable.ID; this.XLMLDataColumnList = xlmlDataTable.XLMLDataColumnList; this.XLMLDataRowList = xlmlDataTable.XLMLDataRowList; } } catch (Exception ex) { this.Exception = ex; } } ... }

  12. Sample Code Data Access Subclass public class XLML { ... protected XLMLDataTableGetXLMLDataTable(SqlDataReadersqlDataReader) { XLMLDataTablexlmlDataTable = new XLMLDataTable(); try { SetDataTableSchema(sqlDataReader, ref xlmlDataTable); SetDataRowList(sqlDataReader, ref xlmlDataTable); } catch (Exception ex) { throw ex; } finally { sqlDataReader.Close(); } return xlmlDataTable; } ... }

  13. Demo

  14. References • Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. Design Patterns. Addison-Wesley Professional Computing Series • Wikipedia – Façade & Façade pattern

More Related