Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Latest commit

 

History

History
42 lines (30 loc) · 972 Bytes

229.md

File metadata and controls

42 lines (30 loc) · 972 Bytes
contributors
zntfdr

Design information flow

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

Define clear responsibilities

  • 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()
  ...
}

Simplify with immutability

Use Swift structs to avoid having objects changing data they're not supposed to change.