3 ms·
MVC itself isn't a tool of craft; it's an ontology for talking about code. That is, there's no system that is or is not MVC; MVC is a guide for mentally modelli
by derefr 11y ago
MVC itself isn't a tool of craft; it's an ontology for talking about code. That is, there's no system that is or is not MVC; MVC is a guide for mentally modelling a system. It's a way to distinguish parts of a continuous whole by drawing imaginary lines, like between having a "brain" vs. a "mind", or between having a "state" vs. a "government", or between various species of plant or animal. They're tools to use to cluster the various actions of messy systems into well-known, recognizable clumps, and assign labels to those clumps, so that when you talk about your system's "controller" and your friend talks about their system's "controller", you both can understand each-other.
Ontological modelling is the pure kind of abstraction—not the kind you reify by implementing it. There's no "MVC design pattern"; all systems can be broken down into MVC. You're never not implementing the "MVC design pattern."
The reason people get confused is that there are design patterns that people implement which make an explicit distinction that looks like MVC. This has nothing to do with MVC; you haven't "implemented MVC" by creating a system where all your model classes are Model classes, and all your views are Views. You've maybe made it easier to reason about your system in MVC terms, but that doesn't get you anything unless "reasoning about your system in MVC terms" is something you need to do a lot, because e.g. you and your coworkers split your responsibilities that way.
Now, what you may have done instead, when you think you've "implemented MVC", is implemented something like Hexagonal Architecture[1]: an actual design pattern—an idea that some-but-not-all codebases are an instance of—involving effectively inverting your "app" into an "engine" of business logic that relies on dependency-injection of engine-specified "pluggable" interfaces for its IO (both the out-to-the-world kind, and the in-to-its-databases and third-party-services kind.)
If your MVC app's "core" business-logic part is a library with direct unit tests on it and so forth, and this part is useless on its own; and if you've got another part that treats the core as a dependency, and turns it into a web service or whatever else—then you've got Hexagonal Architecture. You've also, coincidentally, got some quite-elegantly-delineated MVC boundaries: your model and your view can't share logic, since there's a component boundary between them and neither one can assume anything about the other. But that's just an analytic property of the code; you didn't "do MVC" or even "do MVC right." You just did Hexagonal Architecture, which happens to make it easy to reason about your codebase in MVC terms.
[1] http://fideloper.com/hexagonal-architecture http://fideloper.com/hexagonal-architecture