Hello Teo!
>I don't understand what do you mean by natively, if you mean to:
>- Limit the number of instances
>- automate the instantiation
>- calling in the app
By native singleton pattern class implementation I mean to provide that a class
could be declared as a singleton class and that this singleton class just
instanciates once a single object instance which should be then referenced
every time the class would be referenced. By native implementation I also mean
the conceptual implementation of a singleton classes in harbour.
I'm sure there are lots of ways to get singleton-like behaviour from a class,
but the more examples I see on how to get it, more it sounds like a general
need and more it seems that native implementation would be usefull to the users
(and maybe good to the language too).
The sintax and behaviour I propose would work like the example below
Regards,
Leandro Damasio
EXAMPLE:
=========
Case 1) A singleton class:
<code>
<PRG>
//---------------------------------------------------------------------------------------------------//
CLASS MyClass SINGLETON // THIS IS A SINGLETON CLASS!!!
DATA Status INIT 0
METHOD ChangeStatus() INLINE ::Status := 1
ENDCLASS
*******************************
Procedure Main
*******************************
? MyClass():Status // 0
// first new object is instantiated and kept as the single one
? MyClass():ChangeStatus() // 1
// single object is referred to run :Changestatus()
? MyClass():Status // 1
// single object status has changed
Return
Case 2) A not singleton class:
//---------------------------------------------------------------------------------------------------//
CLASS MyClass // NOT A SINGLETON CLASS!!!
DATA Status INIT 0
METHOD ChangeStatus() INLINE ::status := 1
ENDCLASS
*******************************
Procedure Main
*******************************
? MyClass():Status // 0
// first new object was instantiated
? MyClass():ChangeStatus() // 1
// second new object runs :ChangeStatus()
? MyClass():Status // 0
// third new object is instantiated
Return
</PRG>
</code>
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour