James Edward Gray II wrote:

> If I have an object and I want to increase it's functionality by
> "upgrading/promoting" it to a subclass if certain conditions are met
> during a method call, could/should I use something like:
> 
> sub some_method {
> my $self = $_[0];
> 
> # ...
> 
> if (PROMOTE_CONDITION) {
> $_[0] = Subclass->copy_constructor($self);
> }
> }
> 
> That will change the reference in the calling code, right?  

yes. that's true.

> Any reason I shouldn't do this?

a well define OO design tries to maximize code reuseability and share as 
much as possible. be very careful of the sharing portion as to avoid 
circular reference. if your child reference something in the parent and 
later when the parent upgrade to the child again, the child class return 
back this reference to the newly upgraded object(now a child object), you 
just get youself a circular reference. Perl never warn you able this and as 
you upgrade more and more parent objects to child objects, you create more 
and more circular reference. just watch out for that.

just curious:
if you want child's functionality, why wouldn't you want to have the child 
object in the first place?

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to