views:

94

answers:

1

I'm trying to find a design pattern I can use to simplify the construction of some objects.

Based on an incoming parameter, an custom class, I'm going to create various inheritors from the System.Windows.Forms.Control class.

For instance, if the custom class has one of its members set to 'ChkBox', I want my class to return a System.Windows.Forms.CheckBox, or if the member is 'List' I want my class to return a ComboBox.

public CustomClass()
{
    FieldType type;
}

and

GetControl(CustomClass type);

The common thing is that all the classes I want to create all have Control as it's base class. Having this in mind I imagine there is a way to set the members on the base class in only one place.

Do you know of any design pattern I can use to solve this?

+5  A: 

The factory pattern

decasteljau