Created
December 19, 2012 10:26
-
-
Save rebo/4335787 to your computer and use it in GitHub Desktop.
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
| require 'alias_dci' # !> previous definition of r_z was here | |
| # Class a{ | |
| # void foo(){ | |
| # Print "a"; | |
| # } | |
| # } | |
| class A | |
| include AliasDCI::DataObject | |
| def foo | |
| p "a" | |
| end | |
| end | |
| # | |
| # Class b{ | |
| # role x{ | |
| # void foo(){ | |
| # Print "x" | |
| # } | |
| # Public void foo(){ | |
| # Print "Bar"; | |
| # } | |
| # } | |
| class B | |
| include AliasDCI::Context | |
| role :x do | |
| def foo | |
| p "x" | |
| end | |
| end | |
| def initialize(obj) | |
| assign_named_roles(:x => obj) | |
| end | |
| def foo | |
| in_context do | |
| puts "bar" | |
| end | |
| end | |
| end | |
| # | |
| # Class c<T,K> { | |
| # role y {} | |
| # role z {} | |
| # public c(T y, K z){this.y = y; this.z = z;} | |
| # void Print(){ | |
| # y.foo() | |
| # } | |
| # } | |
| class C | |
| include AliasDCI::Context | |
| role :y | |
| role :z | |
| def initialize(some_t, some_k) | |
| assign_named_roles(:y => some_t, :z => some_k) | |
| end | |
| def print | |
| in_context do | |
| y.foo | |
| end | |
| end | |
| end | |
| # | |
| # Public void Do<T,K>(T someT, K someK){ | |
| # new C(someT,someK).Print(); | |
| # } | |
| def do_it(some_t, some_k) | |
| C.new(some_t, some_k).print | |
| end | |
| class DataObject | |
| include AliasDCI::DataObject | |
| end | |
| # | |
| # | |
| # A plays role of Y in C... | |
| a = A.new | |
| some_data_object = DataObject.new | |
| do_it(a, some_data_object) | |
| # >> "a" | |
| # A also plays role of X in B, and B plays the role of Z. | |
| # | |
| # A's foo should be called because B's context never gets executed, as role Z is never interacted with. | |
| # | |
| b = B.new(a) | |
| do_it(a,b) | |
| # >> "a" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment