[Newbies] Check wheater an instance of a class is actually there or not

Hans Gruber rukin at web.de
Wed Dec 23 02:40:40 UTC 2009


> >>>>> "Hans" == Hans Gruber <rukin at web.de> writes:
> 
> Hans> Now to my question:
> 
> Hans> How may I check wheater an instance of a class (in my case MyFileLibrary) has been created and exists at the time I check it.
> 
> Hans> (MyFileLibrary = nil) is always false.
> 
> Hans> I need this, because wenn an Instance of MyFileLibrary exists at the
> Hans> checking time, I want to proceed with an other method than I want to
> Hans> proceed with when an instance of MyFileLibrary does not exists.
> 
> Sounds like you want the singleton pattern.
> 
> The easiest way to do that is to not create instances at all,
> and just dump all of your methods class side, and all of your "instance"
> variables as "class instance" variables.
> 
> Then treat MyFileLibrary as if it is the only instance that ever exists,
> and has a global name.
> 
> If that's not what you want, explain more.
> 
> -- 
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
> See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
> 

Hi, thanks for the fast answer.

Let me explain my problem a bit more detailed.

I have 3 Morphs and each of them belong to different classes.
What I want to achieve is, that one of the morphs only calls special methods during intialization (in the initialize method) when one of the other morphs has been created before and still exists/is active (so the morph has not been deleted or destroyed).

Maybe some pseudo-code to emphasize my problem:

Initializtion-Method of the morph which dependent initialization:

initialize
 (Class1 = nil) <---- here should be the Check wheater an Object of Class Xy has been created.
 ifTrue: [call special methods]
 ifFalse: [call normal methods]
______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de



More information about the Beginners mailing list