From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA30346; Mon, 5 Aug 2002 19:49:43 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA30458 for ; Mon, 5 Aug 2002 19:49:42 +0200 (MET DST) Received: from ext-nj2gw-3.online-age.net (ext-nj2gw-3.online-age.net [216.35.73.165]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g75HneP16052 for ; Mon, 5 Aug 2002 19:49:41 +0200 (MET DST) Received: from int-nj2gw-4.online-age.net (int-nj2gw-4.online-age.net [3.159.236.68]) by ext-nj2gw-3.online-age.net (8.12.3/8.9.1/990426-RLH) with ESMTP id g75HnWWV015317; Mon, 5 Aug 2002 13:49:32 -0400 (EDT) Received: from uswaumsxbhmedge.med.ge.com (localhost [127.0.0.1]) by int-nj2gw-4.online-age.net (8.12.3/8.12.3/990426-RLH) with ESMTP id g75HnQuD025334; Mon, 5 Aug 2002 13:49:27 -0400 (EDT) Received: by amermsx.med.ge.com with Internet Mail Service (5.5.2656.59) id ; Mon, 5 Aug 2002 12:49:06 -0500 Message-ID: From: "Gurr, David (MED, self)" To: SooHyoung Oh , Caml-List Subject: RE: [Caml-list] How to implement "Singleton" design pattern? Date: Mon, 5 Aug 2002 12:48:49 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2656.59) Content-Type: text/plain; charset="KS_C_5601-1987" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk SML (esp. Mosml) & Ocaml have modules. -D > -----Original Message----- > From: SooHyoung Oh [mailto:shoh@duonix.com] > Sent: Friday, August 02, 2002 10:29 PM > To: Caml-List > Subject: [Caml-list] How to implement "Singleton" design pattern? > > > > It seems that applying design pattern to Ocaml isn't difficult. > While I've been testing some of them, > I found a strange design pattern called "Singleton". > > In Java, "Singleton" design pattern looks like this: > > public class Singleton { > private static Singleton singleton = new Singleton (); > private Singleton () { > ... > } > public static Singleton getInstance () { > return singleton; > } > } > > and in main, it doesn't use "new" but use "getInstance()" for > get THE shared > instance. > > { > ... > Singleton obj1 = Singleton.getInstance (); > Singleton obj2 = Singleton.getInstance (); > ... > } > > I think that the key point of Singleton class is > (1) can't use "new Singleton ()" > because the constructor is private. > (2) "static Singleton singleton" which keeps the only one > Singleton object > and it is shared between all instances. > > The (2) seems to be possible using "Class variable". > And then how can we solve the (1)? > > There are some possible solutions: > (a) invisible class definition in a module > (b) the class definition which can't be called with "new" > (private class ?) > (c) local class definition (in another class definition ?) > > Which one/ones is/are feasible and/or good in Ocaml? > And are there any other solutions? > > --- > SooHyoung Oh > tel: 02)583-8709, 042)861-8649 > cell. phone: 011-453-4303 > web: http://www.duonix.com > > > ------------------- > To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners