In web MVC most designs I\'ve seen, (just choosing model layer as an example) th
ID: 652340 • Letter: I
Question
In web MVC most designs I've seen, (just choosing model layer as an example) the domain problem class, say students, always inherits the superclass "Model." The name is irrelevant, but why do they always inherit classes instead of interfaces?
I've seen others that have interface -> abstract class -> concrete class. But, I don't know why I'd choose a class over an inteface.
Will I need to execute something in the constructor of the superclass in MVC? Some other method?
I know of no mutual functionality that needs an implementation beforehand, but that is probably inexperience? I don't now.
Why not just an interface to enforce my API?
I have seen other answers. I have not seen it in the specific context of MVC design, however.
Using PHP if it matters.
Explanation / Answer
Let's explore the differences between using an interface vs a base class:
If I'm using an interface, that means I need to also implement the, for example, connection logic for each class which wants to connect to the DB. That is a huge pain.
However, if I just subclass a base class (which already provides connection method), then I don't need to keep on implementing it myself. I can just focus on the specialized behavior of the class I'm writing.
So, in cases like this, using a base class over an interface saves me from repeating myself ad nauseum.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.