Take the 2-minute tour ×

Let's say I have a class

    public class Widget
        public int PropA { get; set; }
        public int PropB { get; set; }
        public int PropC { get; set; }

And I have a method

    public Widget CreateWidget(int propA, int propB, int propC)
        Widget w = new Widget();
        w.PropA = propa;
        w.PropB = propB;
        w.PropC = propC;
        return w;

Now, I know that, invariably, Widgets will get more properties over time. Can you recommend a pattern that will prevent me from having to go back in and modify the CreateWidget method every time the Widget object changes, or at least make it easier to maintain?

share|improve this question
The CreateWidget will still work even if you add more properties. And if you need a CreateWidget with more parameters passed in, well... you need to modify it. –  misha Feb 16 '13 at 7:56

1 Answer 1

up vote 0 down vote accepted

You might want to consider Builder Pattern. A decent explanation can be found here.

share|improve this answer

Your Answer


