Facade Design Pattern
1. It is one of structural design pattern.
2. This design pattern provides the simplified interface to the user and hide the complex details.
Checklist:
1. Create a common interface for subsystem.
2. Create one wrapper class which include all the subsystem.
3. Create a object of wrapper class which provide the simplify interface of the larger body of system like a class library.
Implementation:
Here we are implementing the Widget library which is providing the different widgets and there properties in single Object.
1. Implementing the common interface class which contain the properties of widget.
class widget{
void size(int l, int b);
void color(sring color_name);
};
2. implements the widgets with there property by inheriting the interface class widget.
class button:widget
{
void size(int l, int b);
{
cout<<"color button";
}
};
3. Create a Wrapper class "CreateWidget" which encapsulate the widgets with its properties.
class CreateWidget {
widget *mybutton;
public:
CreateWidget()
{
mybutton=new button();
}
void color_button(string color_name)
{
mybutton->color(color_name)
}
void size_button(int l, int b)
{
mybutton->size(int l, int b)
}
}
4. Create a facade class containing the object of CreateWidget class which provide the all widgets and there properties.
class facade{
CreateWidget obj;
obj.color_button("blue");
};
===========================Code=========================================
class widget{
void size(int l, int b);
void color(sring color_name);
};
class button:widget
{
void size(int l, int b);
{
cout<<"color button";
}
void color(sring color_name);
{
cout<<"color button";
}
};
class checkbox:widget
{
void size(int l, int b);
{
cout<<"color button";
}
void color(sring color_name);
{
cout<<"color checkbox";
}
};
class slider:widget
{
void size(int l, int b);
{
cout<<"color button";
}
void color(sring color_name);
{
cout<<"color slider";
}
};
class CreateWidget {
widget *mybutton;
widget *mycheckbox;
widget *myslider;
public:
CreateWidget()
{
mybutton=new button();
mychecklist=new button();
myslider=new button();
}
void color_button(string color_name)
{
mybutton->color(color_name)
}
void color_checkbox(string color_name)
{
mycheckbox->color(color_name)
}
void color_slider(string color_name)
{
myslider->color(color_name)
}
void size_button(int l, int b)
{
mybutton->size(int l, int b)
}
void size_checkbox(int l, int b)
{
mycheckbox->size(int l, int b)
}
void size_slider(int l, int b)
{
myslider->size(int l, int b)
}
};
class facade{
CreateWidget obj;
obj.color_button("blue");
obj.color_checkbox("red");
obj.color_slider("yellow");
obj.size_button(24,36);
obj.size_checkbox(24,36);
obj.size_slider(24,36);
};
Comments
Post a Comment