[Newbies] Login procedure
Ron Teitelbaum
Ron at USMedRec.com
Tue Jun 6 20:20:06 UTC 2006
The problem with not testing my code:
Engine>>start
"start the engine"
[self fuel notEmpty] whileTrue: [
movement := self fuel burnFuelWith: self spark
].
self transmission addMovement: movement
Doesn't move until the gas runs out! :)
So how about:
Engine>>start
"start the engine"
self spark turnOnElectricity.
self engageStarter.
self car isKeyInOnPosition whileTrue: [
self runEngine
].
Engine>>runEngine
"run engine and pass movement to car"
self fuel notEmpty ifTrue: [
movement := self fuel burnFuelWith: self spark
self transmission addMovement: movement
] ifFalse: [
self flashAnnoyingGasGuageLight.
].
Ok I realize I'm probably only amusing myself but just incase it helps
someone I thought I'd point out my mistake!
Happy coding!
Ron
> From: Ron Teitelbaum
> Sent: Tuesday, June 06, 2006 9:43 AM
>
> Hi Marko,
>
> How are things in Finland? I hear it is nice there and there seems to be
> a
> bit of a marketing campaign to get Americans to visit.
>
> Anyway let's get to your question. There are a number of ways to pass
> variables around. The least effective way is to call methods with a lot
> of
> parameters. Usually when I see methods with lots of parameters there is a
> problem and the problem most likely is that the methods is implemented in
> the wrong class.
>
> Consider for a moment an example (since you asked for code examples)
>
> Object subclass: Car
>
> Object subclass: Engine
>
> Object subclass: Fuel
>
> Object subclass: Spark
>
> Now we all know that for engine it run it needs Fuel and Spark so we could
> model the car so that it has each
>
> Car
> instanceVariables: 'engine fuel spark'
>
> Then we have
>
> Car>>start
> "Start the car"
> self engine startWithFuel: self fuel andSpark: self spark onCar:
> self
>
> Engine>>startWithFuel: someFuel andSpark: someElectricity onCar: aCar
> "run the engine"
> [someFuel notEmpty] whileTrue: [
> movement := someFuel burnFuelWith: someElectricity
> ].
> aCar addMovement: movement
>
> Car>>addMovement: someMovement
> "handle the movement of the engine through a transmission"
> self transmission handleMovement: someMovement
>
> Ok so now I'm just amusing myself and thinking of the car being in idle so
> not using the fuel to move at all, wasting gas and promoting global
> warming.
>
>
> Getting back to your question what would happen instead if we have the
> parameters modeled where they are needed. Ask yourself does the car need
> gas and fuel or does the engine need it instead?
>
> So
>
> Car
> instanceVariables: 'engine'
>
> Engine
> instanceVariables: 'fuel spark transmission car'
>
> Now when we build the objects we get much less parameter passing.
>
> Car>>start
> "start the car"
> self engine start
>
> Engine>>start
> "start the engine"
> [self fuel notEmpty] whileTrue: [
> movement := self fuel burnFuelWith: self spark
> ].
> self transmission addMovement: movement
>
> Now this was a long answer to your question and you may be sitting there
> saying; "What does this have to do with databases and buttons"!
>
> Well if you model your parameters in objects they don't need passing.
>
> TestDatabase
> instanceVariables: 'dataSource user password myDBConnection'
>
> Then your button's method #executeTest
>
> TestDatabase>>executeTest
> self myDBConnection on: self dataSource logon: self user password:
> self password.
>
> Where dataSource can have host and port and dbname ...
>
> I hope this helps for specific examples you could try
> http://www.google.com/search?hl=en&q=mysql+squeak
>
> If this doesn't make sense, feel free to ask questions. Let me know how
> it
> goes!
>
> Happy coding!
>
> Ron Teitelbaum
> President / Principal Software Engineer
> US Medical Record Specialists
> Ron at USMedRec.com
>
>
>
> > From: Marko Koivuniemi
> > Sent: Monday, June 05, 2006 4:14 PM
> >
> >
> > Greetings from Finland. I am very excited about Squeak and SmallTalk - I
> > have find myself trying and exploring new programming things and that
> > hasn't happen since days of Commodore 64.
> >
> > Now I am trying to build (with one partner) a program which uses MySQL.
> > I wonder what would be best way to do login screen and actual program.
> >
> > Now we have morphs in windows which has login and password fields and
> > button. At this time idea is that this startup screen test login
> > information and then sends user (or user id) to another screen.
> >
> > I tested various styles and this kind of test "works" with button.
> >
> > test := DatabaseTest new.
> > loginbutton := MyButtonMorph new send: #executeTest to: test";
> > openInHand".
> >
> > But what would be the best way to send many variables or values with
> > button click. (I have couple TextFieldMorphs storing values)
> >
> > I have googled a lot - and most examples deals scriptable buttons. (And
> > that is something I am not familiar with - as a novice I must see code
> > and try different things and see what's happening...)
> >
> >
> > --
> > Marko
> > _______________________________________________
> > Beginners mailing list
> > Beginners at lists.squeakfoundation.org
> > http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
More information about the Beginners
mailing list