3 ms·
> At a code level - no need to write the delegation methods/macros. You don't have to. They're built into SimpleDelegator. Syntactically the difference is you'
by bascule 14y ago
> At a code level - no need to write the delegation methods/macros.
You don't have to. They're built into SimpleDelegator. Syntactically the difference is you'd write:
class MyThing < SimpleDelegator
instead of:
module MyThing
And do:
MyThing.new(obj)
instead of:
obj.extend(myThing)
> At an abstract level - thinking in terms of objects, not classes.
It seems to me like you're trying to use a module to solve a problem which can be solved with an object. I don't think that's thinking in objects at all... it's thinking in modules.
- andyl 14y agoWith DCI do you ever need to extend/include multiple modules? Would this single-inheritance approach work?
- halostatue 14y agoAs long as the interactions you're working with don't implement the same methods, it would be trivially easy: class Account; …; end class Withdrawer < SimpleDelegator; …; end class Depositor < SimpleDelegator; …; end acc = Depositor.new(Withdrawer.new(Account.new)) acc.withdraw(40) acc.deposit(100) At least that's how I understand it. I'm not convinced that DCI is worth it, but…I don't yet have a need for it in the application that I'm working with.