Lazy initialized

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

Lazy initialized

Dalarna Ors
Hi,

As I'm not smalltalk king yet I have some "struggle" with some stuffs from the tutorial.

In this text author write about  lazy initialized .

"
To connect the listed tasks to our newly created task editor we have to add an instance variable taskEditor to ourStRootComponent and create the accessors for it. In addition, it should be lazy initialized with an empty instance ofStTaskEditor. Of course, we could create a new instance for every edit request and thus get rid of the variable, but this would be an unnecessary overhead of object creation.
"

How should I write the code ?

//Dal.

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

Re: Lazy initialized

Michael Perscheid
Hi Dal,

lazy initializing means to create the instance first in the getter accessor.
This looks in Smalltalk like follows:

#taskEditor
        ^ taskEditor ifNil: [taskEditor := StTaskEditor new]

Best regards,
Michael

On 23.02.2014, at 14:18, Dalarna Ors <[hidden email]> wrote:

> Hi,
>
> As I'm not smalltalk king yet I have some "struggle" with some stuffs from the tutorial.
>
> In this text author write about  lazy initialized .
>
> "
> To connect the listed tasks to our newly created task editor we have to add an instance variable taskEditor to ourStRootComponent and create the accessors for it. In addition, it should be lazy initialized with an empty instance ofStTaskEditor. Of course, we could create a new instance for every edit request and thus get rid of the variable, but this would be an unnecessary overhead of object creation.
> "
>
> How should I write the code ?
>
> //Dal.
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

---
Dr.-Ing. Michael Perscheid
[hidden email]

http://www.michaelperscheid.de/

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

Re: Lazy initialized

Dalarna Ors
Hi,

Thank you and have a nice sunday

//Dal.


On Sun, Feb 23, 2014 at 4:23 PM, Michael Perscheid <[hidden email]> wrote:
Hi Dal,

lazy initializing means to create the instance first in the getter accessor.
This looks in Smalltalk like follows:

#taskEditor
        ^ taskEditor ifNil: [taskEditor := StTaskEditor new]

Best regards,
Michael

On 23.02.2014, at 14:18, Dalarna Ors <[hidden email]> wrote:

> Hi,
>
> As I'm not smalltalk king yet I have some "struggle" with some stuffs from the tutorial.
>
> In this text author write about  lazy initialized .
>
> "
> To connect the listed tasks to our newly created task editor we have to add an instance variable taskEditor to ourStRootComponent and create the accessors for it. In addition, it should be lazy initialized with an empty instance ofStTaskEditor. Of course, we could create a new instance for every edit request and thus get rid of the variable, but this would be an unnecessary overhead of object creation.
> "
>
> How should I write the code ?
>
> //Dal.
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

---
Dr.-Ing. Michael Perscheid
[hidden email]

http://www.michaelperscheid.de/

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside