Simple question: in MVC, is it okay for one model to interact with another? For example, with an Auth model...can it interact with the User model - or is there a better way to go about it?
Should the middle man be the controller?
Different Model classes interacting is just fine. Most complex objects aren't completely standalone. As with any good OO code, the classes should use public methods and not expose their implementation to each other, but beyond that, it's all good.
They can certainly know about each other, and utilize each other's functions. Often, best practices will keep this one-way, but not always. Like dj_segfault said, this interaction should be through public methods. Be sure to read up on Dependency injection; changing the internal workings of one class should not break the other, as long as all public methods still behave the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With