Right I dont understand this either. Instead of one file with a few hundred lines of code lots of people prefer 20 classes/files. Drives me nuts.
Right I dont understand this either. Instead of one file with a few hundred lines of code lots of people prefer 20 classes/files. Drives me nuts.
The critical thing here is: these classes reflect terms from the domain model that can be easily intuitively understood, not some made-up abstractions adding to incidental complexity, like -Manager, -Util, -Provider, -Context, -Wrapper, and so on.
Conversely, you can imagine that you wrote a sentence, took some words from it, assumed these words don't exist, and replaced them with their dictionary definitions. Repeat a couple of times and you have your one big class. Extracting classes to capture domain language terms is like reversing this obfuscation/serialization process.
Cool article on the topic: https://www.yegor256.com/2014/11/20/seven-virtues-of-good-ob...
But realistically what happens is, e.g., each franchisee wants us to treat phone number differently than eachother. USA wants no country code. Europe does. Japan wants strict number validation. Taiwan doesn't care. And so on.
At the end of the day it all gets stored as a simple string in the database, and there's software other companies have written that can set it to whatever the hell they want so we have to handle that anyways.
Really all I need is a simple string and a validation function.
https://martinfowler.com/bliki/BoundedContext.html
It is a huge topic. Hard for me to discuss this further without knowing the specifics. But intuitively, if it was as simple as "Really all I need is a simple string and a validation function." then you wouldn't need a class with several hundred lines of code.
Or you could have UsaPhoneNumber, JapanesePhoneNumber, etc.
And instead of doing:
IsValidUsaPhoneNumber(str);
you could do:
var usaPhoneNumber = new UsaPhoneNumber(str);
and now you have the validness captured as a type:
https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...
This is why SRP and this paper are important: They give qualitative guidelines for how to partition systems, not cuter-productive quantitative guidelines.