related:
position | ease | box | interval | due |
---|---|---|---|---|
front | 2.65 | 3 | 6.00 | 2021-10-11T12:26:09Z |
SOLID Object-Oriented Design by Sandi Metz [] extract points from Kent Beck books, SBPP and Implementation patterns book [] from discussion here: https://stackoverflow.com/questions/1866794/naming-classes-how-to-avoid-calling-everything-a-whatevermanager
Summary
guidelines
TDD –> emergent features OOP –> emergent design
Tests
- Without tests refactoring cannot be done to create right abstractions, OOP design, to create maintainable code.
- There should be tests.
- Tests are prerequisites.
Classes
- Right level of abstraction
- not too general, not too specific
- Should represent important concept of problem domain
- Don’t use “er” names
- * they dilute meaning, being very general; managed are plain old data structures and manager is smart procedure.*
- good OOP requires respectable objects with equal partnership, not dumb and smart combo.
- Name class after what they are - not what they do
- https://www.yegor256.com/2014/11/20/seven-virtues-of-good-object.html#6-his-name-is-not-a-job-title
- Naming classes: 99 bottles of OOP
- Creating right abstractions are more important than DRY
- Build good abstraction from concrete examples of code - use triangulation - and then make it DRY.
Methods
- name them after WHAT they do, not after HOW.
- commands -> verb
- queries -> noun
- use name “result” for variable that gets returned; Martin Fowler
- use being verbs with boolean returning names
- is_finished() -> True or False [Kent Beck]
- name of method should be at one higher level of abstraction that its implementation
- not at equal level; not at more than 1 level; just 1 level higher
- much higher level of abstraction will not capture important concept
- equal level does not let any benefit of creating abstraction
- Do not mix levels of abstractions in a method
- things at similar level of abstraction are read easily
Temporary Variables:
- name then after ROLE
- type can be inferred from context
- Smalltalk best practice patterns
- type can be inferred from context
Parameters
- name then after TYPE, esp in dynamic typed languages like python
def salary(anEmployee):
...