Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Storage Object

by jkahn (Friar)
on Sep 11, 2002 at 20:54 UTC ( [id://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.

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://197075]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-18 02:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found