Appearance Mode
Definition:
Provides a consistent interface for a group of interfaces in the subsystem. The appearance mode defines a high-level interface, which makes the subsystem easier to use.
Applicability:
1. When you want to provide a simple interface for a complex subsystem.
2. There is a large dependency between the implementation part of the client program and the abstract class.
3. When you need to build a layered subsystem, use the appearance mode to define the entry points for each layer of the subsystem.
Structure:
Implementation: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + Ly/X08 + left "left"> class ClassA
{
Public:
VoiddoSomethingA ()
{
Cout <"ClassA doSomethingA" <
}
};
Class ClassB
{
Public:
VoiddoSomethingB ()
{
Cout <"ClassB doSomethingB" <
}
};
Class ClassC
{
Public:
VoiddoSomethingC ()
{
Cout <"ClassC doSomethingC" <
}
};
// The encapsulated appearance class, which provides three methods to access the sub-system class
Class Facade
{
Public:
Facade ()
{
M_pa = newClassA;
M_pb = newClassB;
M_pc = newClassC;
}
~ Facade ()
{
If (m_pa)
{
Deletem_pa;
}
If (m_pb)
{
Deletem_pb;
}
If (m_pc)
{
Deletem_pc;
}
}
VoidmethodA ()
{
M_pa-> doSomethingA ();
}
VoidmethodB ()
{
M_pb-> doSomethingB ();
}
VoidmethodC ()
{
M_pc-> doSomethingC ();
}
Private:
ClassA * m_pa;
ClassB * m_pb;
ClassC * m_pc;
};
Facade * pf = newFacade;
Pf-> methodA ();
Pf-> methodB ();
Pf-> methodC ();
Note:
1. subsystems can have multiple appearances. Different modules may require different functions of the method subsystem, so there may be multiple appearances
2. The encapsulated appearance class does not participate in the business logic of the subsystem. This means that the following situations should not occur:
Void methodB ()
{
M_pb-> doSomethingB ();
M_pc-> doSomethingC ();
}
If you do need to do this, it is best to add an encapsulation class independently of ClassB and ClassC.