inheritance v passing object through the constructor

A

aidy

Hi,

Could anyone please tell me what the difference would be of inheriting
a class versus passing that class\object through the initialize
method?

class ErrorBox < Box

end


v

box ||= Box.new

class ErrorBox
def initialize(box)

end

end

And why would I do one over the other?

Thanks

Aidy
 
C

Chris Hulan

Hi,

Could anyone please tell me what the difference would be of inheriting
a class versus passing that class\object through the initialize
method?

class ErrorBox < Box

end

v

box ||= Box.new

class ErrorBox
def initialize(box)

end

end

And why would I do one over the other?

Thanks

Aidy

Try googling "inheritance vs delegation" and "inheritance vs
composition"
Here is a discusin from Perl (http://www.perlmonks.org/index.pl?
node_id=278375), looks to cover the
area pretty good

Artima has a lot of good info, here is an article on inheritence vs
composition (similar to delegation),
http://www.artima.com/designtechniques/compoinh.html

cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top