Skip to content

Instantly share code, notes, and snippets.

@LenKIM
Created July 20, 2019 03:24
Show Gist options
  • Save LenKIM/e84a544c2a0bc60089c3e66ff49d7278 to your computer and use it in GitHub Desktop.
Save LenKIM/e84a544c2a0bc60089c3e66ff49d7278 to your computer and use it in GitHub Desktop.
함수형프로그래밍에서 템플릿메소드
package templates;
abstract class Customer {
def plan
def Customer() {
plan = []
}
def abstract checkCredit()
def abstract checkInventory()
def abstract ship()
def process() {
checkCredit()
checkInventory()
ship()
}
}
---
package templates;
class CustomerBlocks {
def plan, checkCredit, checkInventory, ship
def CustomerBlocks() {
plan = []
}
def process() {
checkCredit()
checkInventory()
ship()
}
}
----
package templates;
class CustomerBlocksWithProtection {
def plan, checkCredit, checkInventory, ship
def CustomerBlocksWithProtection() {
plan = []
}
// BEGIN groovy_customer_blocks
def process() {
checkCredit?.call()
checkInventory?.call()
ship?.call()
}
// END groovy_customer_blocks
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment