Skip to content

Instantly share code, notes, and snippets.

@nicholasjhenry
Created November 5, 2016 15:13
Show Gist options
  • Select an option

  • Save nicholasjhenry/08f1e532f0366631517c0193bac14e21 to your computer and use it in GitHub Desktop.

Select an option

Save nicholasjhenry/08f1e532f0366631517c0193bac14e21 to your computer and use it in GitHub Desktop.
Example from Nat Pryce
// https://groups.google.com/d/msg/growing-object-oriented-software/mCjbhcRAGDs/P7pkf62XBgAJ
interface UserLookup {
fun findByName(name: String): User
}
interface PermissionDecision {
fun rejected(user: User)
fun allowed(user: User)
}
and then the check could be implemented as:
class UserAgeRestriction(val users: UserLookup, val decision: PermissionDecision) {
fun execute(name: String) {
val user = users.findByName(name)
if (user.age > 18) {
decision.rejected(user)
} else {
decision.allowed(user)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment