Re: When is it appropriate to use static methods?
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 05/11/04
- Next message: Randy: "DataGrid and Sorting"
- Previous message: Jon Skeet [C# MVP]: "Re: Convert a String to a char..."
- In reply to: Tom: "Re: When is it appropriate to use static methods?"
- Next in thread: Tom: "Re: When is it appropriate to use static methods?"
- Reply: Tom: "Re: When is it appropriate to use static methods?"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 11 May 2004 19:55:16 +0100
Tom <nfr@nospam.com> wrote:
> "Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
> news:MPG.1b0a94d2e14888a298a89f@msnews.microsoft.com...
> > Tom <nfr@nospam.com> wrote:
> >
> > If your code even *allows* you to create a new instance each time, it's
> > no longer a singleton, by definition.
>
> No. I am using the following format to create my singleton:
>
> namespace Company.TWS.BusinessObject
> {
> public class SummaryBO
> {
> private static TwsDS _twsDS;
> private static string xmlLocation = @"c:\data\tws\tws.xml";
> private SummaryBO() {}
> public static readonly SummaryBO Instance = new SummaryBO();
> public static TwsDS twsDS { get { return _twsDS; } }
>
> [...]
> }
> }
I'm not sure why you've got an instance at all, if everything's static.
The normal singleton pattern would have the _twsDS and twsDS
field/property as an instance, and you'd refer to it using
SummaryBO.Instance.TwsDS
That *doesn't* create an instance each time.
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Randy: "DataGrid and Sorting"
- Previous message: Jon Skeet [C# MVP]: "Re: Convert a String to a char..."
- In reply to: Tom: "Re: When is it appropriate to use static methods?"
- Next in thread: Tom: "Re: When is it appropriate to use static methods?"
- Reply: Tom: "Re: When is it appropriate to use static methods?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|