Created
November 5, 2016 15:13
-
-
Save nicholasjhenry/08f1e532f0366631517c0193bac14e21 to your computer and use it in GitHub Desktop.
Example from Nat Pryce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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