<!-- MHonArc v2.4.4 --> <!--X-Subject: Re: [MUD-Dev] Singleton design pattern (OT?) --> <!--X-From-R13: Oqnz Ivttvaf <nqnzNnatry.pbz> --> <!--X-Date: Tue, 31 Aug 1999 16:43:31 -0700 --> <!--X-Message-Id: Pine.SGI.3.96.990831161311.21900E-100000#zazu,angel.com --> <!--X-Content-Type: text/plain --> <!--X-Reference: 199908312033.PAA18725#laurel,actlab.utexas.edu --> <!--X-Head-End--> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <html> <head> <title>MUD-Dev message, Re: [MUD-Dev] Singleton design pattern (OT?)</title> <!-- meta name="robots" content="noindex,nofollow" --> <link rev="made" href="mailto:adam#angel,com"> </head> <body background="/backgrounds/paperback.gif" bgcolor="#ffffff" text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000"> <font size="+4" color="#804040"> <strong><em>MUD-Dev<br>mailing list archive</em></strong> </font> <br> [ <a href="../">Other Periods</a> | <a href="../../">Other mailing lists</a> | <a href="/search.php3">Search</a> ] <br clear=all><hr> <!--X-Body-Begin--> <!--X-User-Header--> <!--X-User-Header-End--> <!--X-TopPNI--> Date: [ <a href="msg00173.html">Previous</a> | <a href="msg00175.html">Next</a> ] Thread: [ <a href="msg00167.html">Previous</a> | <a href="msg00111.html">Next</a> ] Index: [ <A HREF="author.html#00174">Author</A> | <A HREF="#00174">Date</A> | <A HREF="thread.html#00174">Thread</A> ] <!--X-TopPNI-End--> <!--X-MsgBody--> <!--X-Subject-Header-Begin--> <H1>Re: [MUD-Dev] Singleton design pattern (OT?)</H1> <HR> <!--X-Subject-Header-End--> <!--X-Head-of-Message--> <UL> <LI><em>To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI> <LI><em>Subject</em>: Re: [MUD-Dev] Singleton design pattern (OT?)</LI> <LI><em>From</em>: Adam Wiggins <<A HREF="mailto:adam#angel,com">adam#angel,com</A>></LI> <LI><em>Date</em>: Tue, 31 Aug 1999 16:20:43 -0700 (PDT)</LI> <LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI> <LI><em>Sender</em>: <A HREF="mailto:mud-dev-admin#kanga,nu">mud-dev-admin#kanga,nu</A></LI> </UL> <!--X-Head-of-Message-End--> <!--X-Head-Body-Sep-Begin--> <HR> <!--X-Head-Body-Sep-End--> <!--X-Body-of-Message--> <PRE> On Tue, 31 Aug 1999, Cynbe ru Taren wrote: > > Eli Stevens once said: > > I have been working on the problem of how to best implement the Singleton > > class [1] from _Design Patterns_, by Gamma, et al. in C++. I have wasted a > > lot of time fooling around with this, and now that I have an answer that I > > think I like, I am going to throw it out in hopes that someone else will be > > saved a bit of time. :) > > Last company I worked at (Activerse, a Java outfit) the guys were > threatening to > strangle the next person to implement a Singleton in > company code. Seems like in practice most of them turn out to need multiple > instances sooner or later, and recoding to allow this is a pain. I'm pretty neutral on singletons (it always seemed to me that they don't hold any particular advantage over a global variable), but they are very popular here at Angel. We've been using them heavily in our code for years with nary a complaint. Of course, it's very simple to create one: thanks to some macros we've long used, you only need a single line in the class definition: class foobar { SINGLETON_INTERFACE(foobar); /* rest of class stuff */ }; And one in the .c file itself: #include "foobar.h" SINGLETON_IMPLEMENTATION(foobar); This implements GetInstance() and related functions. Then we usually have a macro for easy access in the .h: #define FOOBAR foobar::GetInstance() Generally we use this for all of the basic game "managers", including input, render, sound, game, AI, and so forth. So the code ends up looking like this: [ ... ] GAME.AddToScore(1000); if (INPUT.ButtonPressed(BTN_3)) /* ... */ crCreature *cr = AI.FindClosestLivingCreature(pos); RENDER.Draw(cr->GetModel(), cr->GetMatrix()); Since they are all just macros, you could always change them to access something else later anyways. But we've never needed to. *shrug* Adam _______________________________________________ MUD-Dev maillist - MUD-Dev#kanga,nu <A HREF="http://www.kanga.nu/lists/listinfo/mud-dev">http://www.kanga.nu/lists/listinfo/mud-dev</A> </PRE> <!--X-Body-of-Message-End--> <!--X-MsgBody-End--> <!--X-Follow-Ups--> <HR> <!--X-Follow-Ups-End--> <!--X-References--> <UL><LI><STRONG>References</STRONG>: <UL> <LI><STRONG><A NAME="00167" HREF="msg00167.html">Re: [MUD-Dev] Singleton design pattern (OT?)</A></STRONG> <UL><LI><EM>From:</EM> Cynbe ru Taren <cynbe#muq,org></LI></UL></LI> </UL></LI></UL> <!--X-References-End--> <!--X-BotPNI--> <UL> <LI>Prev by Date: <STRONG><A HREF="msg00173.html">RE: [MUD-Dev] Re: MUD-Dev digest, Vol 1 #142 - 4 msgs</A></STRONG> </LI> <LI>Next by Date: <STRONG><A HREF="msg00175.html">RE: [MUD-Dev] Re: MUD-Dev digest, Vol 1 #142 - 4 msgs</A></STRONG> </LI> <LI>Prev by thread: <STRONG><A HREF="msg00167.html">Re: [MUD-Dev] Singleton design pattern (OT?)</A></STRONG> </LI> <LI>Next by thread: <STRONG><A HREF="msg00111.html">[MUD-Dev] Monthly FAQ Posting</A></STRONG> </LI> <LI>Index(es): <UL> <LI><A HREF="index.html#00174"><STRONG>Date</STRONG></A></LI> <LI><A HREF="thread.html#00174"><STRONG>Thread</STRONG></A></LI> </UL> </LI> </UL> <!--X-BotPNI-End--> <!--X-User-Footer--> <!--X-User-Footer-End--> <ul><li>Thread context: <BLOCKQUOTE><UL> <LI><STRONG>Re: [MUD-Dev] The Best Guy on the Mud Thing</STRONG>, <EM>(continued)</EM> <ul compact> <LI><strong><A NAME="00459" HREF="msg00459.html">Re: [MUD-Dev] The Best Guy on the Mud Thing</A></strong>, Ilya, Game Commandos <a href="mailto:Ilya#gamecommandos,com">Ilya#gamecommandos,com</a>, Wed 22 Sep 1999, 18:09 GMT </LI> </ul> </LI> <LI><strong><A NAME="00162" HREF="msg00162.html">[MUD-Dev] Singleton design pattern (OT?)</A></strong>, Eli Stevens (KiZurich) <a href="mailto:c718157#showme,missouri.edu">c718157#showme,missouri.edu</a>, Tue 31 Aug 1999, 17:05 GMT <UL> <LI><strong><A NAME="00159" HREF="msg00159.html">Re: [MUD-Dev] Singleton design pattern (OT?)</A></strong>, Wayne Pearson <a href="mailto:wpearson#verity,com">wpearson#verity,com</a>, Tue 31 Aug 1999, 18:22 GMT </LI> </UL> <UL> <li><Possible follow-up(s)><br> <LI><strong><A NAME="00167" HREF="msg00167.html">Re: [MUD-Dev] Singleton design pattern (OT?)</A></strong>, Cynbe ru Taren <a href="mailto:cynbe#muq,org">cynbe#muq,org</a>, Tue 31 Aug 1999, 20:52 GMT <UL> <LI><strong><A NAME="00174" HREF="msg00174.html">Re: [MUD-Dev] Singleton design pattern (OT?)</A></strong>, Adam Wiggins <a href="mailto:adam#angel,com">adam#angel,com</a>, Tue 31 Aug 1999, 23:43 GMT </LI> </UL> </LI> </UL> </LI> <LI><strong><A NAME="00111" HREF="msg00111.html">[MUD-Dev] Monthly FAQ Posting</A></strong>, Ling Lo <a href="mailto:ling#frost,slimy.com">ling#frost,slimy.com</a>, Tue 17 Aug 1999, 22:24 GMT <UL> <LI><strong><A NAME="00115" HREF="msg00115.html">Re: [MUD-Dev] Monthly FAQ Posting</A></strong>, Greg Miller <a href="mailto:gmiller#classic-games,com">gmiller#classic-games,com</a>, Wed 18 Aug 1999, 20:51 GMT </LI> </UL> <UL> <li><Possible follow-up(s)><br> <LI><strong><A NAME="00119" HREF="msg00119.html">RE: [MUD-Dev] Monthly FAQ Posting</A></strong>, Koster, Raph <a href="mailto:rkoster#origin,ea.com">rkoster#origin,ea.com</a>, Wed 18 Aug 1999, 21:28 GMT <UL> <LI><strong><A NAME="00123" HREF="msg00123.html">RE: [MUD-Dev] Monthly FAQ Posting</A></strong>, Ling Lo <a href="mailto:ling#frost,slimy.com">ling#frost,slimy.com</a>, Fri 20 Aug 1999, 22:58 GMT </LI> </UL> </LI> </UL> </LI> </UL></BLOCKQUOTE> </ul> <hr> <center> [ <a href="../">Other Periods</a> | <a href="../../">Other mailing lists</a> | <a href="/search.php3">Search</a> ] </center> <hr> </body> </html>