Created
August 11, 2014 06:36
-
-
Save a-suenami/9eadc3df2bab411dae1b to your computer and use it in GitHub Desktop.
DDD Sample for https://twitter.com/naka_aki_spl/status/498700727942782976.
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
| class Zzz | |
| end | |
| module XxxRole | |
| def behavior_as_x | |
| puts "zzz is xxx." | |
| end | |
| end | |
| module YyyRole | |
| def behavior_as_y | |
| puts "zzz is yyy." | |
| end | |
| end | |
| class XContext | |
| def initialize(zzz) | |
| @zzz = zzz | |
| @zzz.extend(XxxRole) | |
| end | |
| def execute | |
| @zzz.behavior_as_x | |
| end | |
| end | |
| class YContext | |
| def initialize(zzz) | |
| @zzz = zzz | |
| @zzz.extend(YyyRole) | |
| end | |
| def execute | |
| @zzz.behavior_as_y | |
| end | |
| end | |
| zzz = Zzz.new | |
| x_context = XContext.new(zzz) | |
| x_context.execute | |
| y_context = YContext.new(zzz) | |
| y_context.execute |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result