We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Object "self" in classes
Page Index Toggle Pages: 1
Object "self" in classes (Read 698 times)
Object "self" in classes
Mar 10th, 2010, 12:42am
 
I've a syntax question for general object-oriented programming. Is there a way to reference an object "self" within a class?

I do have two classes which are interlinked (say class A and class B).

Within class A I have some arraylists of B objects and some functions act on those objects, calling routines from class B as usual.

However, some of those routines (of class B) would need/change some variables of the calling A object as parameters.

Can I pass the calling object reference somehow? Right now, I can only get what I want by defining the A objects globally, but I do not like this very much.

I know from other languages something like a call of a B-class routine within class A:

B.CallBRoutine(self,....) where "self" refers to the A-object.


An identical problem happens, if I want to call a "global" routine from within class A but need the global routine to know which A-object called it.

I hope I could make my questions clear?

Re: Object "self" in classes
Reply #1 - Mar 10th, 2010, 1:46am
 
It is called this in Java.
Re: Object "self" in classes
Reply #2 - Mar 10th, 2010, 3:44am
 
Thanks!
It would be great if that could get mentioned in the "OOP tutorial" of the reference - whoever is responsible for it.
Page Index Toggle Pages: 1