good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: Be grateful for Perl OOby Steve_p (Priest) |
on Jan 30, 2003 at 15:38 UTC ( [id://231347]=note: print w/replies, xml ) | Need Help?? |
The problem does not seem to be that Perl is better, it just seems like your system is in a serious need for refactoring. Here we go! Step 1 - get a parent class for A and B. If they have the same interface in the code, inforce it and make your life easier. Based one the code, then, SomeFlag and SomeValue become irrelevant, so....
Step 2 - Eliminating the switch...case. Many times, a case statement indicates some problems with the abstraction. So, lets create a new class called SystemCase for our purposes. It will be abstract with a class method called getInstance. Each individual case will be its own object. Since I can't beleive that these cases are only relevant in this chunk of code, this should help elsewhere. Since all of this is decided by the getID() method of p, there are some additional refactorings gained later...
So, that takes the whole chunk of code to...
Eleven lines here, and the code is much more clear than before. You did a great job refactoring the code in Perl, but the same thing can be just as easily done in C++. As I mentioned above, if getID() is determining values to run elsewhere, the above refactoring should help out throughout your system.
In Section
Meditations
|
|