Hi all,
I thought this design point would be interesting, assuming I can make it
sufficiently clearly.
I just did a refactor of my Interfaces work - previously, I had a base class of
Puppet::Interface, and all interfaces were subclasses of that class.
However, once Dan Bode asked for a separation between interfaces that used the
Indirector and those that didn't, I suddently had the base class, a new
Puppet::Interface::Indirector class, and then subclasses of each. Then the
code smell showed up.
Basically, I had to mark the Indirector class as 'abstract', because it's not
actually an interface, it's just another base class. Then I recognized the
pattern that I've been trying to get away from - a base class heirarchy, then
an instance class heirarchy, with almost no instance functionality in the whole
chain.
So, I converted the whole thing - Interface is still the base class, and
Indirector is still a subclass, but all interfaces are just instances of one of
those two (or any other subclass). It works essentially identically, other
than initialization:
Puppet::Interface.new :plugin do
action :download do
....
end
end
But I'm also defining all of the appropriate constants, so adding actions can
be done the same way:
Puppet::Interface::Plugin.action :foo { ... }
As to benefits, primarily it's about general code maintainability. It was
nearly impossible to determine if a given method was base class functionality,
subclass functionality, instance functionality, or what. Here, it's all very
clear and very simple.
There are a few other places that need this same refactor -- notably
Puppet::Type. Hopefully some day. :)
--
SELF-EVIDENT, adj. Evident to one's self and to nobody else.
-- Ambrose Bierce
---------------------------------------------------------------------
Luke Kanies -|- http://puppetlabs.com -|- +1(615)594-8199
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.