A
Austin Ziegler
This is a good question. In the past, I've wished I could change objects into
a different state, sort of like taint or freeze, but with a little more
customization. For example, taking a File object and replacing all of its
write methods to custom ones that log everything written. It can be done by
adding methods (and removing methods ones you don't want to be available
anymore), but I thought a really super simple way to handle the situation is
to simply replace the entire class of the object, so you control 100% what
methods are available. That way, if the File object got passed to some other
method out of your control that called a method you forgot to replace or
remove, the method wouldn't even be there.
I think that Matz is going to provide a much better facility for this
sort of thing with the re and ost method wrappers (AOP-style
programming). The only valuable form of object replacement, IMO, is
replacing a proxy object with a real object.
-austin