Reputation: 8918
Say I have a class like this:
class Foo {
def doFoo() {
println "foo"
}
}
And another like this:
class Bar {
def doBar() {
println "bar"
}
}
And one more that looks like this:
class Baz {
Foo foo = new Foo()
Bar bar = new Bar()
}
With that example, what would it take to be able to use it like this:
Baz baz = new Baz()
baz.doFoo()
baz.doBar()
where the doFoo
and doBar
method calls simply delegate to the defined versions in their respective objects? Is there a way to do this with some kind of metaprogramming, or am I stuck defining each method individually as a wrapper?
Upvotes: 2
Views: 213