On Aug 21, Jeremy Whetzel wrote:
> Hello all!
> 
> I'm planning on playing around with writing some sort of "package
> manager" for source based Linux distros or any of the BSDs.  I'm
> thinking along the lines of Gentoo's portage system or the BSD ports
> system.  I was toying around with modules with this idea, and I got
> to wondering something. If a class needs a lot of different methods,
> such as 30 or 40+ methods, and they're all very specific to that class,
> does it make sense to pull out a bunch of those methods and put them
> into a module and mix them in later, or should they be kept in with the
> class?  For example, if I have an object that represents a software
> tarball, and that object has a number of attributes such as
> dependancies, reverse dependancies, comments, versions, etc, and then I
> have all the methods that go with it for fetching, configuring,
> building, resolving dependancies, etc, would it make more sense to keep
> all those methods out of the class or leave them in the class, even
> though it would make that class huge?
> 
> I realize it's PROBABLY a matter of taste, but are there any good
> reasons to do it one way or another?
> 
> Thanks for any input sent my way...
> 
> Jeremy
> 

My personal sense would be to represent some of these 'attributes' as
members of their own class, i.e. have a Dependency class which you use
through composition.  Your 'Tarball' class would then have a container of
'Dependency' objects (and so forth for other things which have a logical
grouping).

Should there be little in the Dependency class itself, and a lot more
methods that operate on dependencies, then perhaps you make a
DependencyHandler class to which all dependency classes are delegated.

I find that even if it starts real simple and you tell yourself 'Nah, I
don't need a class, I'll just use a String/Hash/Array', that eventually you
end up extending things you want to store and you at least want a Struct
for such a thing.

My personal taste suggests you should not make a module which can't
usefully be mixed in to any other class than the one you have in mind.

You can even have several files, which all contain method definitions for
the one class, grouped by what they do :-P  In some ways I like that better
than a bunch of mixins.

But as you say, it is mostly a matter of taste :)

OT:  Isn't the biggest complaint right now about Gentoo's portage speed?
It's written in Python, but I think you might run into the same problem
with a similar implementation written in Ruby.

--
Brett Williams