I want to call it a "Helper" but this seems way too general.
Let's say I have a class called WidgetCranker
and WidgetCranker
can be set up to crank out widgets of the type Square
, Keyhole
and GearShape
. I can also specify which Color
I want my widgets to be and which Label
I want stamped on them.
Now, setting up each individual instance of WidgetCranker
is fairly involved, the constructor just gives you an empty WidgetCranker
and you have to manually set the type and colour of widgets you want to crank.
WidgetCranker keyholeWidget = new WidgetCranker();
keyholeWidget.Type = WidgetTypes.Keyhole;
keyholeWidget.Color = WidgetColors.Red;
keyholeWidget.Label = "ACME Industries Prototype 1";
But I have a class that requires a lot of WidgetCranker
s that pretty much all look the same except for the label. I want to make my code more readable and less laborious to maintain, so I create a helper class that does all the lifting for me. So the above now becomes:
WidgetCranker keyholeWidget = WidgetCrankerHelper.RedKeyhole("ACME Industries Prototype 1");
My question is twofold:
Is this an actual design pattern and if so, what do we call it? I want to call it a factory, but it most definitely isn't a factory pattern. We're creating exactly the same kind of object in every case, just instantiating them differently. I know it's a type of "Helper", but I want to be more specific than that if I can. It's a helper that does a very specific thing.
Given that "Helper" is a very generic name, I feel that just naming the method by what it produces isn't enough. I should name it so that it's obvious what it does. So would
MakeRedKeyhole
be better orBuildRedKeyhole
? I don't want to useGetRedKeyhole
because that implies we're getting back a reference to an existing instance and not creating a brand new one.