On Sat, 4 Oct 2003 10:59:14 -0500, Eric Wilhelm wrote:
>�I'm working on a module which will eventually be CAD::Drawing
>�Currently, it is named <place where I store modules>::Drawing and
>�the package is declared as simply "Drawing".
>
>�I've run into a wall with my original data structure and have seen
>�a much more flexible and expandable way to do things, so I will be
>�rebuilding the entire module and its children.
>
>�The sub-modules are currently stored under Drawing/*.pm and they
>�all declare their packages as "Drawing". �These modules contain
>�methods and helper functions/constants. �For example,
>�Drawing/Manipulate.pm contains the functions Move, Copy (and lots
>�of other goodies.) �It would not work as a standalone and is not
>�intended to ever be use'd by main. �There is also a file
>�Drawing/Defined.pm which exports a pile of constants, but these
>�only get exported to Drawing.pm and never show up in main (as
>�intended.)
>
>�I've seen the use of @ISA in perltoot, and it looks like this would
>�work, but it does not seem like inheritance is really what I'm
>�doing

No, it doesn't; rather ...

(since the sub-modules aren't really base classes (none of
>�them have (or could have) constructors.)) �If it didn't amount to
>�so many lines, all of the functions could really be contained in
>�one file (but this makes it hard to edit and navigate.)
>
.. that package Drawing is so huge that it's cumbersome to edit and you simply want to 
store some of its publicly callable methods in other packages.  If so, then you could 
simply import the methods from the "sub"-modules using Exporter.

   package Drawing;
   use Drawing::Manipulate qw(Move Copy);
   use Drawing::Defined;
   ...

   package Drawing::Manipulate;
   use Exporter;
   @ISA = ("Exporter");
   @EXPORT = qw(Move Copy);

Seems fine to me.  The constants could be put in a text file holding declarations of 
scalars and 'require'd into package Drawing.

An example of where you would use inheritance in this type of problem is:  You have 
different types of things that you draw, each of which needs a slightly different 
procedure for constructing or initializing the object, but all of which use the same, 
invariant subroutines.  E.g., Drawing::Triangle, Drawing::Pentangle, Drawing::Doodle 
each use a line() method.  In that case I would put line() in Drawing.pm, write 
individual constructors or initializers as needed for each submodule, and then allow 
each submodule to inherit from Drawing via @ISA.

HTH

jimk

Reply via email to