| > > This is not to say "don't use OOP", but rather to say, "think very
> > carefully about if you really need it". Some of the data manipulations
> > Paul mentioned might well benefit from OOP if they require maintaining
> > state information.
>
> Such as keeping track of time? I thought I would do that with an
> exported global value so the user would have free reign to f**k it up
> however they saw fit at any time.
>
Just for the record, perl5 has OO concepts, but is not like the C++ OO concepts
in many respects. Take for example that ALL variables and methods in perl5 are
inherently global unless you take steps to make them not global (like with "my"
and "local" which go away when out of scope). There is also no support for
friends of classes and protected members of classes, which are typically
associated as being part of the OO framework.
In perl5, the basic way to encapsulate is to make packages. All variables and
methods in packages are global to the package, but you can still get at them by
referencing them with their full package name. So, for instance if you have a
main variable foo, and a foo variable in the package bar, you can get at both by
the following:
use FOO;
BAR::foo = 1;
foo = 1;
You can encapsulate a method in a package by explicitly exporting only the
methods that you want to export. Methods that are not explicitly exported are
unavailable outside the package, but within the package, they are, thus concepts
like friends and protected methods within a package are not supported.
Anyway, OO or not, just define a variable for time in the package main, and
users can "have free reign to f**k it up" as much as they want:)
--
Michael Coble, Time Inc. New Media, Pathfinder
Music: http://pathfinder.com/pathfinder/staff/mcoble/music/
Gallery: http://www.panix.com/~coble, representing various artists
Hitman: http://pathfinder.com/pathfinder/staff/mcoble/ |