Hello Mindaugas
I do not see a problems here also. In both my and Teo's sample extra class is created but it i not hidden from "other users around the world" (i.e. MyClass1Real() function is public and visible). It is easy to make this function static and accessible only from same module public funcion (only from MyClass1()).
Yes, you are right.
This could be implemented using preprocessor and magic word SINGLETON, but I do not thing it's something special to be required to implement as a fundamental class feature.
OK. I finally see that although singleton classes are very useful, they are not OOP fundamental and therefore it's not interesting to harbour to implement is as a native OOP feature.
If you'll ever look at .ppo file generated from CLASS sentence you'll be surprised that this CLASS something is actually a function, and that method definitions are only a calls to methods like :AddMethod() of some magic class HBClass() and these :AddMethod() are actually a call to __clsAddMsg(). Just see src/rtl/tclass.prg.
Yes Mindaugas, I understand that. The former solution model I could find was really close to Teo's aproach, but I implemented it directly in hbclass.ch instead of a separete header. Later I took a deeper path and keept the pointer to the singleton instance in the CLASS c structure (class.h) and marked the structure with a boolean flag to indicate wheather a class is singleton, because I was looking forward to implement also a singleton inheritance mechanism, but it revealed as something beyond my technical reach :)
Finally I see that this deeper aproach is not better then the aproach Teo suggested, because there's no official definition (yet) about how should desing patterns interact to OOP fundamentals. Singleton inheritance, for example, is a complicated issue : if class A() is singleton and class B() inherits from A, sould class B be singleton too? Or whatif a third class C() also inherits from A, would the threee of them share the same singleton instance? Its something to be figured out...
Now I'm pretty convinced that Teo's aproach is the most appropriate.
So, you can be sure: if Teo's preprocessor sample is not enough to make you believe you have a real singleton, be sure that you do not have any real class at all, even if you think so.
I believe you understand now what I wanted to mean by a real singleton implementation, don't you?
You are a newbie here, so, Harbour is a little cheating on you ;)
I think you got me! ;) Thank you all for the help! Beat regards Leandro Damasio _______________________________________________ Harbour mailing list (attachment size limit: 40KB) Harbour@harbour-project.org http://lists.harbour-project.org/mailman/listinfo/harbour