While studying DBus code I came across a method that appears to set a class variable and return the value. In DBusConnection>> sessionBus
^SessionBus := self getBus: 0 from: SessionBus
and SessionBus is a class variable. Why return the value? Why not have the sender examine the value of SessionBus? Is it only a matter of style or is this more efficient?
Gary Dunn Open Slate Project http://openslate.org
On 28.02.2011, at 12:06, Gary Dunn wrote:
While studying DBus code I came across a method that appears to set a class variable and return the value. In DBusConnection>> sessionBus
^SessionBus := self getBus: 0 from: SessionBus
and SessionBus is a class variable. Why return the value? Why not have the sender examine the value of SessionBus? Is it only a matter of style or is this more efficient?
#sessionBus is an accessor. This is a lazy initialization.
Besides, from outside the DBusConnection class hierarchy you could not even access the SessionBus class variable.
- Bert -
Wow, a reply right from the author. I am beginning to understand (1%) DBus. Your terrific browser led me to understand I should look for Gnome signals in Gnome, that the solution will need to be platform dependent ... still in the dark how that will pan out. One can learn a lot by reading good code, and I feel like I am learning.
Gary Dunn Open Slate Project http://openslate.org
On Feb 28, 2011 10:58 AM, "Bert Freudenberg" bert@freudenbergs.de wrote:
On 28.02.2011, at 12:06, Gary Dunn wrote:
While studying DBus code I came across a method that a...
#sessionBus is an accessor. This is a lazy initialization.
Besides, from outside the DBusConnection class hierarchy you could not even access the SessionBus class variable.
- Bert -
_______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Hi Gary,
This is a good question.
The code is probably lazily instantiating the variable so that it can be used somewhere else. If the class variable was private to the class and not intended to be used by another class and you were only planning on calling it from the class side then it kinda works. If not; you plan to have an instance call the class variable, or another class needs access to this Class variable, then you need some sort of accessor.
Have a look at SmalltalkImage class variable StartUpList. There is no public accessor for it. There are values in it. Can you find a way to access that list and see what is in it?
You can write code on the class side that references StartUpList (press the class variables button to see the methods that do that, or even highlight StartUpList in a class method of that object and select: Inspect.) but can you find another way?
In many cases you need to access the class variable to get information that is relevant to all the class instances, or to get a single class instance (MyObject class > myDefaultInstnace) from another class so class variable accessors are required.
Ron Teitelbaum
From: beginners-bounces@lists.squeakfoundation.org [mailto:beginners-bounces@lists.squeakfoundation.org] On Behalf Of Gary Dunn Sent: Monday, February 28, 2011 3:07 PM To: Squeak Beginners Subject: [Newbies] Returned values
While studying DBus code I came across a method that appears to set a class variable and return the value. In DBusConnection>> sessionBus
^SessionBus := self getBus: 0 from: SessionBus
and SessionBus is a class variable. Why return the value? Why not have the sender examine the value of SessionBus? Is it only a matter of style or is this more efficient?
Gary Dunn Open Slate Project http://openslate.org
beginners@lists.squeakfoundation.org