Definition:
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.
UML Diagram:
Sample Code:
public sealed class Facade
{
SubSystem1 _subSystem1 = default(SubSystem1);
SubSystem2 _subSystem2 = default(SubSystem2);
SubSystem3 _subSystem3 = default(SubSystem3);
public Facade()
{
_subSystem1 = new SubSystem1();
_subSystem2 = new SubSystem2();
_subSystem3 = new SubSystem3();
}
public void Method1()
{
_subSystem3.Method1();
_subSystem1.Action1();
_subSystem2.Action1();
}
public void Method2()
{
_subSystem1.Action2();
_subSystem2.Action1();
_subSystem2.Action2();
}
}
public class SubSystem1
{
public void Action1()
{
Console.WriteLine("SubSystem1 -> Action1 called");
}
public void Action2()
{
Console.WriteLine("SubSystem1 -> Action2 called");
}
}
public class SubSystem2
{
public void Action1()
{
Console.WriteLine("SubSystem2 -> Action1 called");
}
public void Action2()
{
Console.WriteLine("SubSystem2 -> Action2 called");
}
}
public class SubSystem3
{
public void Method1()
{
Console.WriteLine("SubSystem3 -> Action1 called");
}
}
{
SubSystem1 _subSystem1 = default(SubSystem1);
SubSystem2 _subSystem2 = default(SubSystem2);
SubSystem3 _subSystem3 = default(SubSystem3);
public Facade()
{
_subSystem1 = new SubSystem1();
_subSystem2 = new SubSystem2();
_subSystem3 = new SubSystem3();
}
public void Method1()
{
_subSystem3.Method1();
_subSystem1.Action1();
_subSystem2.Action1();
}
public void Method2()
{
_subSystem1.Action2();
_subSystem2.Action1();
_subSystem2.Action2();
}
}
public class SubSystem1
{
public void Action1()
{
Console.WriteLine("SubSystem1 -> Action1 called");
}
public void Action2()
{
Console.WriteLine("SubSystem1 -> Action2 called");
}
}
public class SubSystem2
{
public void Action1()
{
Console.WriteLine("SubSystem2 -> Action1 called");
}
public void Action2()
{
Console.WriteLine("SubSystem2 -> Action2 called");
}
}
public class SubSystem3
{
public void Method1()
{
Console.WriteLine("SubSystem3 -> Action1 called");
}
}
No comments:
Post a Comment