chanjungskim
08/05/2023, 1:50 AMbod
08/05/2023, 5:53 AMOliver.O
08/05/2023, 11:07 AMchanjungskim
08/05/2023, 2:52 PMOliver.O
08/05/2023, 3:43 PMDatabaseConnectionPool
is "a set of `DatabaseConnection`s, some of which are actively used, while others are cached for re-use". We know what it is right away and have an idea about its characteristics, like probably a limited size, right?
Now suppose, we name it a DatabaseConnectionManager
and define it as "provides `DatabaseConnection`s". In this case, what it actually represents and what its characteristics are is not clear from its name or definition. Of course, we could learn over time how it actually works and internalize that. But getting it will never be as instant as with a properly defined non-manager class.
Another one from the world of UI systems: A View
is "a visualization of a `Model`". A Model
is "data capable of being visualized". In older systems, we find manager classes such as Controller
or Presenter
. We cannot really define what they are. And what they do is somewhat arbitrary. A certain function might sit in a View
or a Controller
. Practically, it may make more sense have it in a Controller
, but this is not clear from the `Controller`'s definition (being just a manager class doing whatever stuff we see fit). Nowadays, in modern UI systems such as Compose you'll no longer find `Controller`s or Presenters
, and these modern systems are way easier to work with.
This all might seem subtle, but in my experience, being disciplined in naming and defining classes according to what they are rather than what they do leads to designs which work better in the long run and are easier to understand for casual readers with infrequent exposure (and that might be your future self).Matteo Mirk
03/11/2024, 3:23 PMchanjungskim
05/02/2024, 8:50 AM