in reply to Class confusion when testing using ref()
Those subclasses seem pointless, as they aren't introducing any new behaviour. The StationaryParticle in particular seems behaviourally identical to its parent class, and the MoveableParticle class doesn't have any behaviour related to movement :(
(In the absence of such behaviour) Perhaps what you wanted instead are so called factory methods e.g.package Particle; ... sub newMoveableParticle { my $class = shift; my $p = $class->new( @_ ); $p->set( 'is_moveable', 1 ); return $p; } sub newStationaryParticle { my $class = shift; my $p = $class->new( @_ ); $p->set( 'is_moveable', 0 ); return $p; }
UpdateThe following is incorrect as kindly pointed out by tobyink
In a long running program, this could cause a memory leak unless you are cleaning up the registry in some way. This could be automated by letting objects 'de-register' themselves when they go out of scope e.g.$REGISTRY{$self} = $self;
End of update What do these objects do anyway? The API seems not very intuitive to me.DESTROY { my $self = shift; delete $REGISTRY{$self}; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Class confusion when testing using ref() (isa crock)
by tye (Sage) on Jan 05, 2014 at 23:35 UTC | |
by Anonymous Monk on Jan 06, 2014 at 02:03 UTC | |
Re^2: Class confusion when testing using ref()
by tobyink (Canon) on Jan 07, 2014 at 19:33 UTC |
In Section
Seekers of Perl Wisdom