• (cs) in reply to luis.espinal
    luis.espinal:
    I guess that guy never heard of n-sized object pools.

    He "invented" them. He called the pattern "N-tons", but you have to manually code each n.

  • Jay (unregistered) in reply to JavaDummy
    JavaDummy:
    This is the worst C# code I have ever seen. All those c Pound developers need to switch to a real language like vb.

    Or RPG.

  • Jay (unregistered) in reply to frits
    frits:
    luis.espinal:
    I guess that guy never heard of n-sized object pools.

    He "invented" them. He called the pattern "N-tons", but you have to manually code each n.

    My spell-checker rejects the words "n-sized" and "N-tons".

  • EngleBart (unregistered)

    Another WTF is initializing a local variable to null in Java when you do not need to... In this case there is no problem with it, but in many cases it could create the potential for a NullPointerException.

    Let the compiler do its job! Don't poke it in the eye and blind it!

    Plus it will waste one CPU cycle.

    No this is not a troll.

  • localboy (unregistered) in reply to Anonymous

    BART only has one stop in Fremont, and it's at the end of the line.

  • Peter (unregistered) in reply to RancidBeans

    I wonder if this Singleton has an implementation of Inversion of Control, and there is a method to inject the Spring context it so desperatly wants.

    Something like

    public static setPubContext(ClassPathXmlApplicationContext pubContext) {
    	PublicationService.pubContext = pubContext;
    }

    I think it expects the Spring context to be injected from the outside before calling getInstance()

    When the instance is requested and the Spring context is aleady known, the instance is taken from Spring.

    If there is no Spring context, a new instance is created by initalizing Spring as specified in the applicationContext.xml. In there, the bean would be fully described with all its dependency injections. This new Spring context then becomes the context where the bean will be taken from on subsequent calls.

    pubContext = ctxt;

    The only issue remaining is the caller of getInstance get a different instance then the one Spring creates, but both instances share all the statics Spring can inject, if not a Singleton then it is like a siamese twin for sure. The first instance will only be used by the caller, neither Spring or the Singleton keep refereces to it, it can be garbage collected as soon as the caller does not need it anymore, then only the one instance controlled trough Spring remains.

    The example can do the singleton behaviour, but by itself it expects Spring to be in control over it. Take away Spring and it's out of control. If control has to be done trough other means then Spring, just instantiate trough the public constructor, inject all dependencies and keep your own reference.

  • (cs) in reply to Jay
    Jay:
    JavaDummy:
    This is the worst C# code I have ever seen. All those c Pound developers need to switch to a real language like vb.

    Or RPG.

    equips rocket propelled grenade

  • foo (unregistered) in reply to Rootbeer
    Rootbeer:
    foo:
    Brand me a troll, but seriously, WTF?!?!?

    Your comment boils down to "I admit knowing nothing about the dominant programming paradigm of the past 15-20 years, yet I must inform you how stupid YOU ALL are."

    Why should you not be branded a troll?

    Because reading this discussion, I don't see where anyone can come up with a definitive explanation of a simple concept. I'm not saying anyone is stupid, I'm saying that the "dominant programming paradigm" sure sounds like bullshit to me.

    If the "experts" can't come up with and agree on a simple, canonical description of how a simple programming problem should be dealt with, then I think the paradigm is broken.

  • Jimmy Jones (unregistered)

    Coming soon....the Tripleton

  • Malcolm Dugdale (unregistered)

    The 'Doubleton' was (first?) featured in Steven Goodwin's book "Cross platform game programming". Damned if I can remember how/why it was useful, though!

  • Drak (unregistered) in reply to Malcolm Dugdale
    Malcolm Dugdale:
    The 'Doubleton' was (first?) featured in Steven Goodwin's book "Cross platform game programming". Damned if I can remember how/why it was useful, though!

    Obviously to alternate between two platforms :)

  • Aaron (unregistered)

    Was alex looking at the same code i am? Nothing he says here makes any sense.

    "The instance variable is not static". The instance variable does not store the singleton instance; it is used to temporarily store the return value. The guy could have changed his code to "return new PublicationService(CONTEXTFILES);" instead, but the way he has it follows the one-path-in one-path-out rule which has its merits.

    "The constructor grabs an instance of the class out of spring." No, the constructor does not do this. The constructor initializes the spring context.

    "The first time you call getInstance, if has to create 2 instances". This is also not true. If I call PublicationService.getInstance(), it either loads a bean from the spring application context, or it creates a new instance. It will never create 2 instances.

    The stupidest thing I see about this code is that it treats loading a spring application context as "not an error", so the application, when running, has kind of a schrodinger's cat kind of design where the PublicationService is maybe a singleton, and maybe not. There is also a minor WTF that he initializes instance to null, when it is guaranteed to be initialized in the if/else block. So, it's not a perfect design, but.... it seems like everyone is completely misinterpreting the code here?? Am i missing something obvious?

    Apologies if someone else already pointed all this out. I came late to the party and just kind of skimmed the 3 pages of comments.

  • (cs) in reply to foo
    foo:
    Rootbeer:
    foo:
    Brand me a troll, but seriously, WTF?!?!?

    Your comment boils down to "I admit knowing nothing about the dominant programming paradigm of the past 15-20 years, yet I must inform you how stupid YOU ALL are."

    Why should you not be branded a troll?

    Because reading this discussion, I don't see where anyone can come up with a definitive explanation of a simple concept. I'm not saying anyone is stupid, I'm saying that the "dominant programming paradigm" sure sounds like bullshit to me.

    If the "experts" can't come up with and agree on a simple, canonical description of how a simple programming problem should be dealt with, then I think the paradigm is broken.

    So anyone who can operate a browser is an OOP "expert"? Come on, now.

  • The Duke (unregistered) in reply to Eternal Density
    Eternal Density:
    Jay:
    JavaDummy:
    This is the worst C# code I have ever seen. All those c Pound developers need to switch to a real language like vb.

    Or RPG.

    equips rocket propelled grenade

    Damn, I'm looking good!

  • Antho (unregistered)

    And of course, you forgot about the class PublicationService being final when it has a protected constructor! Right, you never know. Maybe in a moment of weakness the compiler could actually allow someone to override it?

  • Robert (unregistered)

    Some details are more important than intent !!!

  • Jordan (unregistered) in reply to Steve A
    Steve A:
    [W]hy does [Kristopher] spell his name with a 'K'[?]

    Maybe that's how his parents spelled it?

  • Rick (unregistered)

    The real Doubleton Pattern

    http://www.codeproject.com/KB/architecture/designpattern_doubleton.aspx?fid=179369&df=90&mpp=25&noise=3&sort=Position&view=Quick

Leave a comment on “The Doubleton Pattern”

Log In or post as a guest

Replying to comment #:

« Return to Article