Mid From PDF GoF Patterns Gang of Four Patterns

Client Code (Application):?

  • The Application class accepts an IUIFactory in its constructor. This

means the client code can choose which concrete factory (Windows or Mac)

to use without changing the Application class itself.

public class Application
{
private readonly IButton _button;
private readonly ICheckbox _checkbox;
public Application(IUIFactory factory)
{
_button = factory.CreateButton();
_checkbox = factory.CreateCheckbox();
}
public void Render()
{

_button.Render();

_checkbox.Render();

}
}

More from Design Patterns in C#

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details