Oxygen Basic
Information => Reference => Topic started by: kryton9 on May 07, 2011, 12:15:06 AM
-
Also can we use the Singleton pattern. For my game engine, I am hoping that by just creating a new instance of it I can create everything else and keep track via the CGLAPP so that it is very easy for users.
It would create default items and the user can just get them with defaults or be able to modify them via getters and setters for their needs.
-
Hi K9,
I don't know what's the meaning of GETTERS and SETTERS ?
Do you mean type setter ? ???
-
Kent,
I think I understand what singleton means: A class which has only one object belonging to it.
This is a way of encapsulating sets of global variables and devices into objects so that no conflicts can occur in the global namespace.
Some of my larger examples could benefit from this :)
This is not quite Singleton but one way to do it is create a class whose members are all static. Then it can be instantiated anywhere access is needed.
An object of this class has no body of its own but provides access to the static properties and methods shared with all the others.
I mention it here because it is simpler and faster than using a conventional singleton.
'====================
class SharedObject
'====================
'
'
static sys a,b,c
'
'MORE STATIC PROPERTIES HERE
'
'
'ACCESSOR METHODS HERE (getters and setters)
'
end class
SharedObject u
SharedObject w
u.c=42
print w.c
Charles
-
Hi K9,
I don't know what's the meaning of GETTERS and SETTERS ?
Do you mean type setter ? ???
Peter, in classes you can have private variables. This means that a user can't directly access the data in those variables. They need to use getters and setters to access the private variables, this gives controlled access to the data by the class. This is one of the major benefits of classes, and is named encapsulation.
Here is an example in this thread Peter.
http://www.oxygenbasic.org/forum/index.php?topic=168.0
-
Thanks Charles, nice to know that it is doable.