Short summary: When you want to predefine certain instantiations of a class, is it better to create subclasses or a factory?
Problem Context
I have a view helper class MyWebserviceUrl that has a bunch of properties. It's purpose is to generate an url.
I would like to be able to have preconfigured instances of this class, so that I don't have to do so many setThis()
, setThat()
for the same family of MyWebserviceUrl
's
If I have an url of type a
, I would like to get an instance with some defaults that pertains to this type a
.
I can solve this by subclass MyWebserviceUrl
like so
UrlFamFoo extends MyWebserviceUrl {…}
UrlFamBar extends MyWebserviceUrl {…}
I could also create a factory, that given a parameter like 'Foo' can configure a MyWebserviceUrl
object for me.
My questions:
- Should I go the subclass route, or the factory one?
- If you advice a factory, should this be a
- separate view helper,
- normal factory class, or
- method
factory($name)
inMyWebserviceUrl
?
Sidenote: I am currently developing in Zend Framework, but this question is more general I think.
edit1 →To be more specific: I just need some of the properties set to defaults and the rest set on the fly.