Re: Static Classes ... in response to B. Voigt's comments

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Peter Duniho wrote : "... However, as far as your question goes, it seems to
me that one obvious difference between a static class and the singleton
pattern is that a singleton, being an instanced object, can implement
interfaces and inherit other classes.

The two share a lot in common, I'll grant. But I don't think that a static
class is inherently a singleton itself."

Some good points there to think on, Peter. Appreciated. One thought that
occurs to me is to wonder (I guess I'll have to go back to the "epiphany" as
revealed by the Gang of Four to check on it) if the "original" concept of a
Singleton had any reference to Interfaces or Inheritance. But that could
just turn out to be a pedantic quest. Me like Interfaces, Rhino or no Rhino.

The thought also comes that most of us writing WinForms applications make
use of a Static class, Program.cs, every time we use the default WinForms
app template to start a new project :) Of course that's not a Singleton
since you can run multiple copies of the .exe. I've seen a variety of ways
to make sure one-and-only-one instance of your app runs.

So maybe I should be careful to distinguish between Singleton as a pattern
that enforces one-and-one-only of some object, and "Singleton" as a method
of having a single-instance-at-a-time-running in the context of WinForms
apps ?

Interfaces, as contracts that enforce, appeal to me but I keep sometimes
wondering why there isn't an Interface "flavour" that specifies the scoping
of what it requires you code : i.e., that says, in effect : "when you
inherit from this Interface, you must implement this as static, this as
public, and this as private readonly." From an "enforcement" point of view
I like that, but realize it's really not what Interfaces as we have them now
are.

best, Bill





.



Relevant Pages

  • Re: Static Classes ... in response to B. Voigts comments
    ... Singleton had any reference to Interfaces or Inheritance. ... no one would ever see the private member except the class implementing it. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: singleton vs static
    ... > Advantages of Singleton: ... GoF's Design Patterns book says itself that it's not an OO primer, ... during which these interfaces are sucked back out ... It's often appropriate to design a Facade interface as the only way to ...
    (comp.object)
  • Re: Can use of singletons denote poor project design?
    ... Daniel Parker wrote: ... Program State: Again a central point to keep track of program status. ... "It is a truth universally acknowledged, that a singleton in possession ... Model, View, and Controller interfaces. ...
    (comp.object)
  • Re: singleton vs static
    ... >Many times I find myself considering a singleton and then realizing a static ... * Derivatives of Singletons are not necessarily Singletons ... * Intrusive Semantics, changing from singleton to ... Advantages of static class ...
    (comp.object)
  • Re: Are global variable evil?
    ... I think that there is no ideal solution, at least not one that works ... > With regards to the static class method (not encapsulating a singleton) ...
    (microsoft.public.dotnet.languages.csharp)