DAY 20
πΒ μ€λ μ½μ λ²μ : 10μ₯ ~ Cohesion
<aside>
π μ±
μμ κΈ°μ΅νκ³ μΆμ λ΄μ©μ μ¨λ³΄μΈμ.
</aside>
- The first rule of classes is that they should be small. βHow small?β We count responsibilities.
- The name of a class should describe what responsibilities it fulfills. The more ambiguous the class name, the more likely it has too many responsibilities.
- We should also be able to write a brief description of the class in about 25 words, without using the words βif,β βand,β or βbut.β
- The Single Responsibility Principle: Class should have one responsibility.
- Getting software to work and making software clean are two very different activities. The problem is that too many of us think that we are done once the program works. We fail to switch to the other concern of organization and cleanliness.
- So the question is: Do you want your tools organized into toolboxes with many small drawers each containing well-defined and well-labeled components? Or do you want a few drawers that you just toss everything into?
- The primary goal in managing such complexity is to organize it so that a developer knows where to look to find things and need only understand the directly affected complexity at any given time.
- When cohesion is high, it means that the methods and variables of the class are co-dependent and hang together as a logical whole.
<aside>
π€ μ€λ μ½μ μκ°μ? λ μ€λ₯΄λ μκ°μ κ°λ³κ² μ μ΄λ³΄μΈμ
</aside>
As the book is focused on Java specifically, Iβm not sure to which level I need to follow the advice. I never write Class but I think this is a good learning for me to understand the backend code.
<aside>
π κΆκΈν λ΄μ©μ΄ μκ±°λ, μ μ΄ν΄λμ§ μλ λ΄μ©μ΄ μλ€λ©΄ μ μ΄λ³΄μΈμ.
</aside>
<aside>
π‘ μκ° 3μ€ μμ½
</aside>
- Class should have one responsibility. If you notice the Single Responsibility Principle is abused, itβs likely that the person didnβt come back to organize or clean the code after she got it working.
- You want toolboxes with many small drawers each containing well-defined and well-labeled components. This is easy for others to understand and use it too.