Design - Composition
Don’t design with interfaces, discover them - Rob Pike Duplication is far cheaper than the wrong abstraction - Sandi Metz
Animal type is not required to implement Dog and Cat. Design for behaviour not data types.
Embed types for behaviour and not reusable state. Don’t create animal type with name
as a state just to re-use it for Dog and Cat.
Ways to tackle a problem, drafting a solution Start with the primitives > low level API > High level API
Don’t start with interfaces, use concrete data types.
When do you declare that the code is done ?
- When we have 100% test coverage for happy path and 70% test coverage overall
- When we know that our code is decoupled enough.
Discover smaller interfaces first, then compose for larger interfaces. Only write interfaces only if we already have working implementations. Write concrete implementation first, then interface implementation.
Assertions
using bracket notation, we can do type checks or interface checks. If the var implements this method, etc.
Interfaces describe behaviour. A smell could be when an interface is a noun.