FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   Processing & OO ?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Processing & OO ?  (Read 438 times)
kib


Processing & OO ?
« on: Sep 6th, 2004, 8:21pm »

Hi all !
 
I am new at processing and I cannot find any documentation about classes etc ...
 
Do I have to refer to the Java in a Nutshell book ?
 
What I would like you to tell me is :
 
+ why can't I write things such as :
 
Code:

class Aclass {
  private static Aclass me;
    Aclass() {
 // instructions
    }
 
    public static Aclass getReference () {
 if (me != null) me = new Aclass();
 return me;
    }
     
}

 
(actually, i would like to use the singleton pattern)
 
+ then, is there any mean to delete an object ? or to reset it : the "this = new ClassName()" thing does not work.
 
 
Thank you very much
And sorry for my poor English.
 
fry


WWW
Re: Processing & OO ?
« Reply #1 on: Sep 7th, 2004, 5:37am »

you can't use that specific piece of code since by default, a processing sketch is a single class file that gets the "public class YourSketch extends BApplet" wrapped around it. as such, any classes that you make are inner classes, which cannot have static methods.
 
if you write all the "public class" stuff for your sketch, you'll be able to do full "java" mode programming. but i'd just recommend moving 'Aclass me' outside of the class def and things will work fine.
 
kib


Re: Processing & OO ?
« Reply #2 on: Sep 7th, 2004, 11:40am »

thank you very much
 
liminal


Re: Processing & OO ?
« Reply #3 on: Sep 8th, 2004, 5:29pm »

Just a word of caution if you're using static variables in an applet. The variables will tend to stick around between page refreshes, but other parts of the applet state, that these variables indirectly refer to, might become invalid.  
 
So, either take a great deal of care to initialize and deinitialize your static variables during the applet lifecycle methods, or better, avoid using them.
 
At least that's been my experience... YMMV
 
Pages: 1 

« Previous topic | Next topic »