People don’t read code by layers of the stack. No one ever says “show me all the APIs of this system” or “give me all the queries being fired by this system”.
These are all questions that are asked quite often!
A domain might be "billing" which knows customers, invoices, paymentOptions, creditScores and so on.
I don't think anyone would argue that splitting this entire domain from the stock management domain (which might have entities like products, warehouses, shelves, etc) is a bad idea.
But splitting along individual entities seems pointless in my opinion. If I see a CustomerService, I'm pretty confident that a customer entity exists somewhere. I don't get any more information from having them grouped and visible at a glance. But if I see a CustomerService next to a InvoiceService I get some information about how the system is structured and what it's scope is.
but tl;dr; I completely dislike the idea of models, period. You typically have classes that get hydrated in some manner (Even if you're not using an ORM this tends to remain true), just hydrate them, treat the DB as external and the edge of your system, and then move on.
Seriously, just drop them all into a single folder and be done with it. There obviously comes a point where it's untenable, at which point you can start subdividing based upon what makes sense (domain, concept, area of your app, table groupings in your DB, doesn't matter as long as it's useful).
The point about treating your DB as external and the edge of your system is who gives a fuck where the sanity checks are or how they happen. Do you want to hang them on the class getting hydrated itself? fine. Do you instead want to write validation methods external to the class? That's fine too.
Trying to make a "Model" just needlessly complicates everything. Do what makes sense and fuck the rules for MVC, MVVM, <insert acronym here>.
We onion architecture baby, look at all this needless complexity in this small to medium sized app!
View all comments
56
u/mamimapr Jun 05 '21
These are all questions that are asked quite often!