caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Gurr, David (MED, self)" <David.Gurr@med.ge.com>
To: SooHyoung Oh <shoh@duonix.com>, Caml-List <caml-list@inria.fr>
Subject: RE: [Caml-list] How to implement  "Singleton" design pattern?
Date: Mon, 5 Aug 2002 12:48:49 -0500	[thread overview]
Message-ID: <D4DBD8568F05D511A1C20002A55C008C09C294FD@uswaumsx03medge.med.ge.com> (raw)

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


             reply	other threads:[~2002-08-05 17:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-05 17:48 Gurr, David (MED, self) [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-08-03  5:29 SooHyoung Oh
2002-08-03 17:42 ` Tim Freeman
2002-08-05  9:28 ` Hendrik Tews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D4DBD8568F05D511A1C20002A55C008C09C294FD@uswaumsx03medge.med.ge.com \
    --to=david.gurr@med.ge.com \
    --cc=caml-list@inria.fr \
    --cc=shoh@duonix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).