These programs are the same, except one instantiates the weapon when
instantiation the object and one instantiates the weapon the the
initialize method itself. They both work the same.
Which way is better?
class Character
def initialize(weapon)
@weapon = weapon
end
.
.
end
class King < Character
end
king = King.new(AxeBehaviour.new)
VS
class Character
def initialize(weapon)
@weapon = weapon.new
end
.
.
end
class King < Character
end
king = King.new(AxeBehaviour)