Naming #2 — Naming as a design pillar
🔎 The relationship between naming and the single responsibility principle (SRP) is strong.
🧑💻 SRP states that every system component, such as a module, class, function, or state, should have only one responsibility and should be separated from other responsibilities.
⁉️ But, how can we determine if a component has more than one responsibility?
💡For the past few years, I have been using naming to address this issue and it has proven to be an effective solution.
⚒ Naming is an excellent way to reflect and enforce the SRP, as it can clearly indicate the responsibilities within the name.
Here are a few examples:
✅ A class named "UserAuthenticator" clearly indicates that it is responsible for handling user authentication tasks.
❌A class named "UserManager" may indicate that its scope is too large, which is a sign of poor design. God class?
✅ A function named "loginOrSignup" endorses multiple responsibilities. Clearly.
So it is well identified and can be easily reworked.
❌ A function signature "login(Boolean emailExists)" is an indicator of code smell, as the flag may be used to decide between login or sign up.
☝️That said, you can use names to identify SRP violations and make design adjustments at all levels.
🤓 However, to do so effectively, it is important to master naming techniques, such as "outside-in naming," which I briefly discussed in my previous post
Keep learning ! keep reading !
Happy coding !