contributors |
---|
zntfdr |
Truth vs. derived values:
- Where is truth?
- Who really knows that state which one place should be consulted for it?
- Values derived from truth are in many ways like a cache and needed to be treated as such
- Think of the inputs and outputs
- Separate out responsibilities from the rest of the program
- Use composition to build up larger pieces from smaller ones
Example: validators.
protocol Validator {
validateWithError(error: NSErrorPointer) -> Bool
}
- Definition of “input” left open to interpretation
For example:
class SignUpValidator: Validator {
let usernameValidator = UsernameValidator()
let setPasswordValidator = SetPasswordValidator()
let emailAddressValidator = EmailAddressValidator()
...
}
Use Swift structs to avoid having objects changing data they're not supposed to change.