"be consistent" | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
My one point of critique is: ->new doesn't only create but also initializes objects. This is wrong, simply because (in an inheritance situation) you want to create only one object (call ->new, bless it into a class), but initialize the object to work with not only the class itself, but one or more superclasses. If creation and initialization are forced together, that gets awkward. By design, Class::InsideOut doesn't provide new(). Users are free to combine creation and initialization, or to separate them, based on personal preference and design needs. Somewhere along the line, register() has to be called, but that's the only requirement. I'm supporting of people subclassing Class::InsideOut to provide a new/init structure. (I intend to do one myself when I get a chance.) A minor point of critique is that you seem to be cache-ing inheritance data that could change at run time. The cache could get out of sync. Technically, it caches at run-time at the point of first use. E.g., the first time DESTROY is called, the cache is built. Hopefully, at that point, any run-time @ISA manipulations are done. I'd also like to point out a novel (to my knowledge) method to do desctruction of inside-out objects. Instead of following the inheritance tree, you can look at the object and see which classes it is initialized to. With a little collaboration from the user, you can see that by inspecting which field hashes have existing keys with the object's id. The field hashes of these classes must be cleared (and their DEMOLISHers called). By ignoring @ISA you wind up having to search through all registered properties. From looking at your code, it looks like your approach searches through all properties to generate a list of classes and then iterates back over those classes to do the destruction. That's seems to me like a potentially big computational hit for a DESTROY method -- particularly if lots of inside-out classes exists and if lots of objects are created and destroyed. Class::InsideOut uses @ISA and the cache to try to minimize the inevitable overhead of DESTROY. While the caching might be a little too aggressive a form of early optimization, I think @ISA is a good way of avoiding having to do an exhaustive search. That said, I think your code is an interesting start at an alternative. If you decide to continue developing it, I suggest you look at the slides from my talk on inside-out objects for ideas on some of the incremental features you may want to support. (You may find that doing so will complicate the elegance of your design.) -xdg Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk. In reply to Re^2: Introducing Class::InsideOut
by xdg
|
|