What is the Facade Design Pattern in C Sharp .Net ?
Article 5 on design patterns-
The Facade Design Pattern
The Facade Design Pattern is a structural design pattern that provides a unified interface to a set of interfaces in a subsystem. It is used when you want to simplify a complex system by providing a simple interface. Here is an example of the Facade Design Pattern in C#:
using System;
public class SubsystemA
{
public void MethodA()
{
Console.WriteLine("SubsystemA Method");
}
}
public class SubsystemB
{
public void MethodB()
{
Console.WriteLine("SubsystemB Method");
}
}
public class SubsystemC
{
public void MethodC()
{
Console.WriteLine("SubsystemC Method");
}
}
public class Facade
{
private readonly SubsystemA _subsystemA;
private readonly SubsystemB _subsystemB;
private readonly SubsystemC _subsystemC;
public Facade()
{
_subsystemA = new SubsystemA();
_subsystemB = new SubsystemB();
_subsystemC = new SubsystemC();
}
public void Operation1()
{
Console.WriteLine("Operation 1\n" +"-----------");
_subsystemA.MethodA();
_subsystemB.MethodB();
_subsystemC.MethodC();
}
public void Operation2()
{
Console.WriteLine("Operation 2\n" +
"-----------");
_subsystemB.MethodB();
_subsystemC.MethodC();
}
}
class Program
{
static void Main()
{
Facade facade = new Facade();
facade.Operation1();
facade.Operation2();
Console.ReadKey();
}
}
You may also like: What is SEO Ranking | How SEO Ranking Matters in Search Optimization? | How to Improve Your SEO Ranking? | Why SEO Ranking Fluctuates ?
Leave a Reply
Please log in to comment on this post.