Fri , Aug 04 2023
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();
}
}
I am an engineer with over 10 years of experience, passionate about using my knowledge and skills to make a difference in the world. By writing on LifeDB, I aim to share my thoughts, ideas, and insights to inspire positive change and contribute to society. I believe that even small ideas can create big impacts, and I am committed to giving back to the community in every way I can.
Leave a Reply