Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Two remarks about the Perl object model (http://www.velocityreviews.com/forums/t951255-two-remarks-about-the-perl-object-model.html)

Rainer Weikusat 08-22-2012 09:30 PM

Two remarks about the Perl object model
 
Negative one first: Destructors of superclasses aren't executed
automatically when an instance of a subclass with a destructor of its
own is destroyed. This implies that, in order to derive a class from
some other class, knowledge about the implementation of all ancestors
of the new class is required because a suitable order and mechanism to
cause superclass destructors to be executed needs to be worked out.

The positive one: A class is created by associating a reference to an
object of some type with a package. This is accomplished by calling
the bless-subroutine with suitable arguments. Because this is just an
ordinary runtime-operation, references which are already blessed into
a particular package can be 're-blessed' into a different package in
order to become an instance of a different class.

Example where this is useful: For a 'firewall-configuring application'
I need to manage sets of 'IP addresses' which are composed of objects
representing a single address and objects representing an address
range. An operation I need to perform on two such sets is to do an
ordered merge of them. This requires being able to merge any two
objects making up a continuous range into an equivalent, single range
object. If I can do destructive merging (usual case), this is
implemented by calling a method named change_addrs on the object
'containing' the new end-address of the combined range. If this
happens to be an object representing a single address, the method
transparently morphs that into a range object.


All times are GMT. The time now is 09:55 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57