I'm fiddling with an MVC framework, and I stumbled upon a problem I'm not sure how to solve.
I want to make a DomainObjectFactory
for the Model layer of my application, however, each Domain object would have a different set of arguments, for instance:
- Person - $id, $name, $age.
- Post - $id, $author, $title, $content, $comments
- Comment - $id, $author, $content
And so on. How can I easily tell my factory what kinds of object do I require?
I've came up with several options:
- Pass an array - I dislike this one, because you can't rely on the constructor's contract to tell what the object needs for his work.
- Make the
DomainObjectFactory
an interface, and make concrete classes - Problematic, because that's an awful lot of factories to make! - Use Reflection - Service locator much? I don't know, it just seems that way to me.
Is there a useful deign pattern I can employ here? Or some other clever solution?