Explanation:
Another option is to use a Factory class. This is a design pattern that is explained in the book Design Patterns by the Gang of Four. (You can find it at www.amazon.com or any large bookstore. Most large libraries also have a few copies laying around.) The basic principle is to have an object that will create objects for you, given some set of information.
The reason why this is useful is that you encapsulate most, if not all, of the class information. The code using these objects only need to know that they need a Porsche or a Boeing747, not that they need a Vehicle::Car::Porsche or a Vehicle::Air::Boeing747. Now, the usefulness of this pattern for you is that you can have your reblessing logic hidden within this Factory class.
Design Patterns contains a number of other ideas that may be useful here. One is the Veneer. (It's got other names, but that's the one I remember.) The idea is that you have some object - call it a Window. Now, you might have some Windows with borders and some Windows without borders.
One way to solve this problem is to create a Window class and a BorderWindow class. Not a big deal. Another solution is to have the Window class know how to handle borders. Again, not a big deal.
What if you have 10 options instead of just 1? That's over 1000 classes or a large set of if-else statements, just to deal with one change in how the object is displayed on the screen.
So, what you do is create your Window class and you also create a Border class. The Border class is very small and handles all methods the Window class does. All has is a reference to the Window class and maybe a few attributes for itself. It delegates all calls back to the Window class, except for the Paint() method, which it does a few things, then delegates.
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
In reply to Re: Dynamicly controlling @ISA and namespaces
by dragonchild
in thread Dynamicly controlling @ISA and namespaces
by nothingmuch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |