No registered users in community xowiki
in last 10 minutes
in last 10 minutes
Re: [Xotcl] Help with singleton design pattern
From: Uwe Zdun <uwe.zdun_at_wu-wien.ac.at>
Date: Tue, 22 Apr 2003 22:17:06 +0200
Hi,
I just had the idea for yet another Singleton variant that was not exactly
planned for in the XOTcl design, but seems to work fine: an object that has
itself as a class (and Class as a superclass so that it stays a class):
% Class A -superclass Class -class A
that means it can define instprocs on it and dispatch them directly:
% A instproc aProc args {puts ****}
% A aProc
****
procs do also work:
% A proc bProc args {puts ++++}
% A bProc
++++
and you can derive a subclass from the Singleton:
% Class B -superclass A
::B
% B b
::b
% b aProc
****
and it conforms to the "Singleton definiton" (a class that has just one
instance).
--Uwe
On Tuesday 22 April 2003 21:21, Artur Trzewik wrote:
> Hallo!
>
> As singleton objects I often use Objects directly derived from Object
>
> Object MySingleton
> MySingleton proc doJob {} {
> puts "This is my job"
> }
>
> MySingleton doJob
>
> This is not singleton pattern but is same cases you do not need some
> Java, C++ solution.
> One disadvantage is that you can not use method inheritance.
>
> By the way.
> The presented solution from G. Neumann.
> That is to overwrite "new" method that returns singleton object
> is the standard way to implements singleton in Smalltalk
> (the singleton instance is saved in class variable Default).
> That is XOTcl! "new" is just method not special operator and can
> be overwritten.
>
> Artur Trzewik
>
>
> _______________________________________________
> Xotcl mailing list - Xotcl_at_alice.wu-wien.ac.at
> http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
Date: Tue, 22 Apr 2003 22:17:06 +0200
Hi,
I just had the idea for yet another Singleton variant that was not exactly
planned for in the XOTcl design, but seems to work fine: an object that has
itself as a class (and Class as a superclass so that it stays a class):
% Class A -superclass Class -class A
that means it can define instprocs on it and dispatch them directly:
% A instproc aProc args {puts ****}
% A aProc
****
procs do also work:
% A proc bProc args {puts ++++}
% A bProc
++++
and you can derive a subclass from the Singleton:
% Class B -superclass A
::B
% B b
::b
% b aProc
****
and it conforms to the "Singleton definiton" (a class that has just one
instance).
--Uwe
On Tuesday 22 April 2003 21:21, Artur Trzewik wrote:
> Hallo!
>
> As singleton objects I often use Objects directly derived from Object
>
> Object MySingleton
> MySingleton proc doJob {} {
> puts "This is my job"
> }
>
> MySingleton doJob
>
> This is not singleton pattern but is same cases you do not need some
> Java, C++ solution.
> One disadvantage is that you can not use method inheritance.
>
> By the way.
> The presented solution from G. Neumann.
> That is to overwrite "new" method that returns singleton object
> is the standard way to implements singleton in Smalltalk
> (the singleton instance is saved in class variable Default).
> That is XOTcl! "new" is just method not special operator and can
> be overwritten.
>
> Artur Trzewik
>
>
> _______________________________________________
> Xotcl mailing list - Xotcl_at_alice.wu-wien.ac.at
> http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
-- Uwe Zdun Department of Information Systems, Vienna University of Economics Phone: +43 1 313 36 4796, Fax: +43 1 313 36 746 zdun_at_{xotcl,computer,acm}.org, uwe.zdun_at_wu-wien.ac.at