Thu 7th March Kevin Jones
Our goal is to produce flexible, maintainable, defect free code.
Code:
- Automate the build and deploy process
- Don't leak UI in to domain layers
- Don't leak DB access across layers
- Define new types for each concept even if they are small
- e.g. Money type rather than using a double.
- Build facades
- Amalgamate behaviour in to a new type
- Hide complexity of underlying objects
- Single responsibility principle
- Using concrete types is often a bad idea
- Code to interfaces
- Can replace real objects with test objects
- Can use Dependency Injection
- Use of 'new' means we are tied to an implementation
- Tests should be isolated
- Unit tests shouldn't use system (file / DB etc.)
- Test names should be descriptive (use the BDD style)
- Given_When_Than()
- e.g. GivenAUserService_WhenIAskForAllUsers_ThenAllUsersAreReturned()
- Arrange -> Act -> Assert
- Parameter injection
- Setter injection
- Constructor injection
- Use an IoC container (e.g. Unity / Castle / Ninject / AutoFac for MVC)
- IoC (Inversion of Control) is a principal, Dependency Injection is a consequence of IoC
No comments:
Post a Comment