On 31 July 2012 07:54, Intransition [email protected] wrote:
For what it’s worth, I kind of like this solution, but I get the
feeling there’s something not quite right about it. An alternative
could be to strategically name source files, and
appropriate one; in that case each version-specific file could
redefine the relevant part of Main. E.g.
def initialize version
# universal code
# version-specific code
It splits things up into maintainable files quite nicely, and also has
less parsing (for what that’s worth.) However it wouldn’t work if you
need two different versions of Main in the one program.
Alternatively you could create a factory, which is essentially what
you’ve done, but might be a bit more recognisable to, or better
understood by, maintainers. E.g.
# … universal code
class MainV0 < Main
# … version-specific code
def self.create version
It’s mostly a fluff change to what you’ve already got, but it means
each object has the version-specific API as their class rather than a
mixed-in module (i.e. no real difference as far as I’m aware), and
it’s clear that the MainFactory is a factory and that each of the
MainVx classes are what it instantiates, whereas a partially
implemented Main class with some strange magic in its #initialize
method might be a bit less clear.
That all said good documentation will almost always trump recognisable
patterns or otherwise self-documenting code.
I’d be interested to see other peoples’ comments.
Matthew K., B.Sc (CompSci) (Hons)
“You’ll never find a programming language that frees
you from the burden of clarifying your ideas.” - xkcd