librelist archives

« back to archive

Mixin/inheritance 'require' style question

Mixin/inheritance 'require' style question

From:
Peter Fitzgibbons
Date:
2012-01-16 @ 18:34
HI Folks,

This is partly a style question (and partly a question to resolve my
current monkey-hacking)

I have a collection of modules/classes :
Shoes   => ./lib/shoes.rb
Shoes::App  => ./lib/shoes/app.rb - requires 'shoes', 'shoes/window',
'shoes/layout'
Shoes::Window  => ./lib/shoes/window.rb - requires 'shoes'
Shoes::Layout  => ./lib/shoes/layout.rb - requires 'shoes'
Shoes::Native => ./lib/shoes/native.rb - requires 'shoes'
Shoes::Button => ./lib/shoes/button.rb - requires 'shoes/native'

So, I have done this two ways, and both seem to have pros/cons :
Option 1 :
All requires in the base module, so ./lib/shoes.rb has :
require 'shoes/window'
require 'shoes/app'
require 'shoes/native'
require 'shoes/button'

Options 2 :
Each file requires exactly what it needs, so ./lib/button.rb has :
require 'shoes/native'
Then ./lib/native.rb has :
require 'shoes'

Which is most desireable?
This may start a conversation of inheritance vs. mixin, and questioning
_why's original class-structure.  I'm open to that conversation.

Thoughts and comments?

Peter Fitzgibbons
(847) 859-9550
Email: peter.fitzgibbons@gmail.com
IM GTalk: peter.fitzgibbons
IM AOL: peter.fitzgibbons@gmail.com

Re: [shoes] Mixin/inheritance 'require' style question

From:
J. Kaiden
Date:
2012-01-16 @ 21:17
hi Peter,

  interesting question - i've done both, and i find that the advantage of
including everything needed by all separate classes/modules in the base is
that if you share requirements between classes/modules, you only have to
require them once - cutting down on overhead.

  suppose you've got a bunch of custom widgets that use the observer
pattern to communicate...  you could require 'observer' in all of them, or
just require it once in the main app that ties all of those widgets
together.

  the disadvantage i see to this method is that when looking at the
separate classes/modules, it can be difficult to know what that class or
module requires in and of itself.

  my two cents...

  - j




On Mon, Jan 16, 2012 at 7:34 PM, Peter Fitzgibbons <
peter.fitzgibbons@gmail.com> wrote:

> HI Folks,
>
> This is partly a style question (and partly a question to resolve my
> current monkey-hacking)
>
> I have a collection of modules/classes :
> Shoes   => ./lib/shoes.rb
> Shoes::App  => ./lib/shoes/app.rb - requires 'shoes', 'shoes/window',
> 'shoes/layout'
> Shoes::Window  => ./lib/shoes/window.rb - requires 'shoes'
> Shoes::Layout  => ./lib/shoes/layout.rb - requires 'shoes'
> Shoes::Native => ./lib/shoes/native.rb - requires 'shoes'
> Shoes::Button => ./lib/shoes/button.rb - requires 'shoes/native'
>
> So, I have done this two ways, and both seem to have pros/cons :
> Option 1 :
> All requires in the base module, so ./lib/shoes.rb has :
> require 'shoes/window'
> require 'shoes/app'
> require 'shoes/native'
> require 'shoes/button'
>
> Options 2 :
> Each file requires exactly what it needs, so ./lib/button.rb has :
> require 'shoes/native'
> Then ./lib/native.rb has :
> require 'shoes'
>
> Which is most desireable?
> This may start a conversation of inheritance vs. mixin, and questioning
> _why's original class-structure.  I'm open to that conversation.
>
> Thoughts and comments?
>
> Peter Fitzgibbons
> (847) 859-9550
> Email: peter.fitzgibbons@gmail.com
> IM GTalk: peter.fitzgibbons
> IM AOL: peter.fitzgibbons@gmail.com
>