Jump to content

Object generation


phenam

Recommended Posts

With the idea of "code to an interface, not an implementation", does this mean that we shouldn't be instantiating models directly within controllers?  For example, if I was accepting user registration information, is it ok for me to instantiate a user model to put the input data into, or is it better to go through some factory class/other method to create my model?

Link to comment
https://forums.phpfreaks.com/topic/218239-object-generation/
Share on other sites

With the idea of "code to an interface, not an implementation", does this mean that we shouldn't be instantiating models directly within controllers?  For example, if I was accepting user registration information, is it ok for me to instantiate a user model to put the input data into, or is it better to go through some factory class/other method to create my model?

 

Generally, most people try to keep their controllers thin.  The controller is the crossing guard - it should pass data along to where it should go (the model, the view), but it shouldn't be responsible for actually manipulating it beyond that.  Even with ORMs, many people create Repository objects to act as a facade in order to keep the model details hidden from the controller.

Link to comment
https://forums.phpfreaks.com/topic/218239-object-generation/#findComment-1132472
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.