set variables before initialize and write out files before exit

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

set variables before initialize and write out files before exit

Joseph Alotta
Greetings,

My object needs to have some variables set before it can run the initialize method and also it needs to have run an exit method.

f := FileParser new.
f inPath: '/Users/jja/Desktop/accountingfiles/'.
f readThis: 'rei mastercard.csv'.
f process
f outPath: '/Users/jja/Desktop/accountingfiles processed/'.
f write.  


Is there a better way to do this?

Sincerely,

Joe.


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: set variables before initialize and write out files before exit

Ron Teitelbaum
Hi Joe,

I'm not sure in what context you mean.  Why wouldn't you run this in the
#initialize method?

JoeAccountingParser class>>configure
        InPath := '/Users/jja/Desktop/accountingfiles/'.
        OutPath := '/Users/jja/Desktop/accountingfiles processed/'.

JoeAccountingParser >>initialize
        self class configure.
        fileParser := FileParser new.
        fileParser inPath: self class InPath.
        fileParser outPath: self class OutPath.

JoeAccountingParser class >> process: aFile
        ^(self new) process: aFile; yourself.
         

JoeAccountingParser process: aFile
        fileParser readThis: aFile.
        fileParser process.
        fileParser write.

This is a bit refactored and it uses the configure method I recommend to you
earlier.  This configure method could be anything including a method to read
an external file for details.

Solutions like a factory method pattern come to mind if you don't want to
use #initialize.

JoeAccountingParser class >> process: aFile from: inPath to: outPath

There is also Behavior #startUp and #shutDown on the class side.

See Smalltalk #addToStartUpList: #addToShutDownList:

These fire when an image is started or shutdown.  

I think a bit more explanation of what problem you are having is needed.

All the best,

Ron Teitelbaum



> From: Joseph Alotta
> Sent: Friday, June 10, 2016 12:23 PM
>
> Greetings,
>
> My object needs to have some variables set before it can run the
initialize

> method and also it needs to have run an exit method.
>
> f := FileParser new.
> f inPath: '/Users/jja/Desktop/accountingfiles/'.
> f readThis: 'rei mastercard.csv'.
> f process
> f outPath: '/Users/jja/Desktop/accountingfiles processed/'.
> f write.
>
>
> Is there a better way to do this?
>
> Sincerely,
>
> Joe.
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: set variables before initialize and write out files before exit

Joseph Alotta
thanks Ron, I hadn’t thought about class variables.  

sincerely,

Joe.


> On Jun 10, 2016, at 12:17 PM, Ron Teitelbaum [via Smalltalk] <[hidden email]> wrote:
>
> Hi Joe,
>
> I'm not sure in what context you mean.  Why wouldn't you run this in the
> #initialize method?
>
> JoeAccountingParser class>>configure
>         InPath := '/Users/jja/Desktop/accountingfiles/'.
>         OutPath := '/Users/jja/Desktop/accountingfiles processed/'.
>
> JoeAccountingParser >>initialize
>         self class configure.
>         fileParser := FileParser new.
>         fileParser inPath: self class InPath.
>         fileParser outPath: self class OutPath.
>
> JoeAccountingParser class >> process: aFile
>         ^(self new) process: aFile; yourself.
>          
>
> JoeAccountingParser process: aFile
>         fileParser readThis: aFile.
>         fileParser process.
>         fileParser write.
>
> This is a bit refactored and it uses the configure method I recommend to you
> earlier.  This configure method could be anything including a method to read
> an external file for details.
>
> Solutions like a factory method pattern come to mind if you don't want to
> use #initialize.
>
> JoeAccountingParser class >> process: aFile from: inPath to: outPath
>
> There is also Behavior #startUp and #shutDown on the class side.
>
> See Smalltalk #addToStartUpList: #addToShutDownList:
>
> These fire when an image is started or shutdown.  
>
> I think a bit more explanation of what problem you are having is needed.
>
> All the best,
>
> Ron Teitelbaum
>
>
>
> > From: Joseph Alotta
> > Sent: Friday, June 10, 2016 12:23 PM
> >
> > Greetings,
> >
> > My object needs to have some variables set before it can run the
> initialize
>
> > method and also it needs to have run an exit method.
> >
> > f := FileParser new.
> > f inPath: '/Users/jja/Desktop/accountingfiles/'.
> > f readThis: 'rei mastercard.csv'.
> > f process
> > f outPath: '/Users/jja/Desktop/accountingfiles processed/'.
> > f write.
> >
> >
> > Is there a better way to do this?
> >
> > Sincerely,
> >
> > Joe.
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > [hidden email]
> > http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://forum.world.st/set-variables-before-initialize-and-write-out-files-before-exit-tp4900437p4900450.html
> To start a new topic under Squeak - Beginners, email [hidden email]
> To unsubscribe from Squeak - Beginners, click here.
> NAML