Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^3: Call Grandparent Method, Skipping Parent

by Dallaylaen (Hermit)
on Jun 20, 2013 at 13:21 UTC ( #1039976=note: print w/replies, xml ) Need Help??

in reply to Re^2: Call Grandparent Method, Skipping Parent
in thread Call Grandparent Method, Skipping Parent

Why not refactor XXX into ZZZ (which holds everything but XXX->setup) and XXX which inherits from ZZZ and only has distinctive setup? YYY can now inherit from ZZZ as well.
WWW (+setup) WWW (+setup) +-XXX (+setup) => +-ZZZ +-YYY +-XXX (+setup) +-YYY

Replies are listed 'Best First'.
Re^4: Call Grandparent Method, Skipping Parent
by QM (Parson) on Jun 21, 2013 at 12:13 UTC
    Why not refactor XXX into ZZZ...
    Yes, but the point is to avoid refactoring existing code where possible.

    The Long Story

    My team has inherited a large codebase of resource libraries. Due to the man-years required to refactor this into something that fits the use model, the team is making use of the existing codebase. (Eventually, something may replace it, or we may move on to something completely different.)

    This is a system to test real hardware, firmware, and software in multiple systems communicating with each other, the test controller, and other interested auxilliary systems. The core of the codebase is an "event loop" system that polls multiple remote systems, registers events to trigger at specific times, and registers signal handlers listening for certain kinds of responses. (Some issue with threads was apparently encountered at inception, so this is a polling system using RPC or somesuch.)

    Our current aim is to write stand-alone tests for various components and features. The base class that all tests use is capable of handling nested tests, such that with a little forethought, all tests can be run concurrently in the "event loop" system. The base class registers all nested tests, and runs through all setup methods, then all initiate methods, then all complete methods, then all teardown methods. While the execution path is not threaded, multiple events on multiple systems can occur concurrently or simultaneously (depending on the nature of the events). Properly structured tests are written as modules, which can then be used (nested) in other tests, ad nauseum.

    The point of my question was to discover a practical way to layer tests upon tests, with minimal rewriting of existing tests. Since everything is in a formal system with code reviews and releases, it is important not to go refactoring big swaths of code to add a minor bit of coverage to the suite of tests.

    I've swept a lot of details under the rug, and while there is some leeway to change direction, we can't incur a lot of refactoring time. There is a moderate but growing list of test scripts, so any global refactoring decision should be made as soon as possible.

    Ultimately, I think we'll have to refactor the big methods into smaller ones, and call into the parent(s) at a refined level to do only the bits needed, and not just rewrite a larger method (with considerable duplication). (I've probably left something out, but I'll stop here for now.)

    Quantum Mechanics: The dreams stuff is made of

      Well, I'm not talking about refactoring as in "a great adventure", but rather about a small and controlled change - spawning an empty subclass, then moving one method "as is" into that subclass.

      Given the circumstances you describe, this may be dangerous too. For instance, someone may already have started calling methods by full name. Or, maybe, the setup() method shares some global variables with the rest of the code. Still my suggestion was nowhere near "rewriting all the code to make it better"!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039976]
and monks are getting baked in the sun...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2018-05-26 00:52 GMT
Find Nodes?
    Voting Booth?