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}; }
In reply to Re: Class confusion when testing using ref()
by Arunbear
in thread Class confusion when testing using ref()
by atcroft
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |