Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
go ahead... be a heretic
 
PerlMonks  

Re: Storage Object

by jkahn (Friar)
on Sep 11, 2002 at 20:54 UTC ( #197075=note: print w/ replies, xml ) Need Help??


in reply to Storage Object

You might consider one of the following:

  1. Put the Storage object in a package variable within the Source and Destination classes.

    (in Source and Destination):

    our $storage; # or: # our Storage $storage; # I think this works to type it

    and in your main code:

    use Storage; my $storage = new Storage(); use Source; use Destination; $Source::storage = $storage; $Destination::storage = $storage; my $input = 'source.txt'; while (<IN>) { $source = new Source($_); $destination = new Destination(); $source->storeData(); $destination->useData(); }
  2. Pass the Storage object into the constructor of each of the Source and Destination objects:

    in your Source and Destination classes, add code to handle setting a Storage object as a parameter to new().
    then in your main code:

    use Storage; my $storage = new Storage(); use Source; use Destination; my $input = 'source.txt'; while (<IN>) { $source = new Source($_, storage => $storage); $destination = new Destination(storage => $storage); $source->storeData(); $destination->useData(); }
Personally, I prefer the latter solution, since that allows you in the future to have different Storage objects for different Source and Destination objects.


Comment on Re: Storage Object
Select or Download Code
Re: Re: Storage Object
by artist (Parson) on Sep 11, 2002 at 21:36 UTC
    Thank Jkahn
    use Storage; my $storage = new Storage(); use Source; use Destination; $Source::storage = $storage; $Destination::storage = $storage;
    Works for now. I don't know how elegant it is though. It's good for me since I just need a single storage object for the entire file rather than seperate objects. Let's say my storage object is pointing to a database.
    2nd solution is considerd good for different storage objects

    art of storage
    of
    an artist.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://197075]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2014-04-18 09:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (464 votes), past polls