Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. I have a horrible feeling I've been using a pattern for years...

I have a horrible feeling I've been using a pattern for years...

Scheduled Pinned Locked Moved The Lounge
comregextutorialquestionlearning
43 Posts 20 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • OriginalGriffO OriginalGriff

    I use this when the instances are going to be resource heavy - maybe have a couple of images in them - and / or I want one example of each instance through the whole system. So I have a private constructor, a static Dictionary containing all created instances, and a static method which fetches the instance:

    private static Dictionary all = new Dictionary();
    private MyClass(string name, List data )
    {
    ...
    all.Add(name, this);
    }
    public static MyClass Get(string name, List data)
    {
    if (all.ContainsKey(name)) return all[name];
    return new MyClass(name, data);
    }

    And it works really well. But ... is that a pattern? I hope not, I might have to stop using it ... :~

    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

    J Offline
    J Offline
    Jorgen Andersson
    wrote on last edited by
    #4

    It's called the OriginalPattern

    Wrong is evil and must be defeated. - Jeff Ello

    J OriginalGriffO 2 Replies Last reply
    0
    • J Jorgen Andersson

      It's called the OriginalPattern

      Wrong is evil and must be defeated. - Jeff Ello

      J Offline
      J Offline
      Jeremy Falcon
      wrote on last edited by
      #5

      You had me going for a split second there.

      Jeremy Falcon

      OriginalGriffO 1 Reply Last reply
      0
      • J Jeremy Falcon

        You had me going for a split second there.

        Jeremy Falcon

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #6

        I admit I googled ... mostly Beer companies, which may be appropriate.

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        J J 2 Replies Last reply
        0
        • J Jorgen Andersson

          It's called the OriginalPattern

          Wrong is evil and must be defeated. - Jeff Ello

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #7

          :laugh: That's actually a pretty good name for it, considering!

          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          J 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            I use this when the instances are going to be resource heavy - maybe have a couple of images in them - and / or I want one example of each instance through the whole system. So I have a private constructor, a static Dictionary containing all created instances, and a static method which fetches the instance:

            private static Dictionary all = new Dictionary();
            private MyClass(string name, List data )
            {
            ...
            all.Add(name, this);
            }
            public static MyClass Get(string name, List data)
            {
            if (all.ContainsKey(name)) return all[name];
            return new MyClass(name, data);
            }

            And it works really well. But ... is that a pattern? I hope not, I might have to stop using it ... :~

            Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #8

            PIEBALD rolls a three and reaches for his GOF book... The closest I see is Proxy, but that's more about deferred instantiation. As mentioned by others, it's also close to Singleton, yet possibly Singleton done right. (The standard Singleton Pattern is filth.) Maybe this could be called the Library Pattern. Anyway, I do that a lot too. Most recently as a store for RegEx instances which I use frequently.

            1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              I use this when the instances are going to be resource heavy - maybe have a couple of images in them - and / or I want one example of each instance through the whole system. So I have a private constructor, a static Dictionary containing all created instances, and a static method which fetches the instance:

              private static Dictionary all = new Dictionary();
              private MyClass(string name, List data )
              {
              ...
              all.Add(name, this);
              }
              public static MyClass Get(string name, List data)
              {
              if (all.ContainsKey(name)) return all[name];
              return new MyClass(name, data);
              }

              And it works really well. But ... is that a pattern? I hope not, I might have to stop using it ... :~

              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

              E Offline
              E Offline
              Eytukan
              wrote on last edited by
              #9

              Flyweight?

              Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy Falcon.

              1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                I use this when the instances are going to be resource heavy - maybe have a couple of images in them - and / or I want one example of each instance through the whole system. So I have a private constructor, a static Dictionary containing all created instances, and a static method which fetches the instance:

                private static Dictionary all = new Dictionary();
                private MyClass(string name, List data )
                {
                ...
                all.Add(name, this);
                }
                public static MyClass Get(string name, List data)
                {
                if (all.ContainsKey(name)) return all[name];
                return new MyClass(name, data);
                }

                And it works really well. But ... is that a pattern? I hope not, I might have to stop using it ... :~

                Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #10

                OriginalGriff wrote:

                But ... is that a pattern?

                Yes, it is. I would refer to it as the static OGDictionarySingleton.

                OriginalGriff wrote:

                I hope not, I might have to stop using it

                Why? The definition of a pattern is a piece of reusable code that solves a given problem. Does your manager not allow for tested and documented solutions?

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                OriginalGriffO 1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  I admit I googled ... mostly Beer companies, which may be appropriate.

                  Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                  J Offline
                  J Offline
                  Jeremy Falcon
                  wrote on last edited by
                  #11

                  :-D

                  Jeremy Falcon

                  1 Reply Last reply
                  0
                  • L Lost User

                    OriginalGriff wrote:

                    But ... is that a pattern?

                    Yes, it is. I would refer to it as the static OGDictionarySingleton.

                    OriginalGriff wrote:

                    I hope not, I might have to stop using it

                    Why? The definition of a pattern is a piece of reusable code that solves a given problem. Does your manager not allow for tested and documented solutions?

                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #12

                    Because most patterns are a waste of time, but worshipped as the One True Holy Grail of Computing by those that learn it. And then force all applications they write to fit that pattern regardless of the appropriateness.

                    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    L K 2 Replies Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      Because most patterns are a waste of time, but worshipped as the One True Holy Grail of Computing by those that learn it. And then force all applications they write to fit that pattern regardless of the appropriateness.

                      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #13

                      OriginalGriff wrote:

                      Because most patterns are a waste of time, but worshipped as the One True Holy Grail of Computing by those that learn it. And then force all applications they write to fit that pattern regardless of the appropriateness.

                      ..you are interacting with the wrong kind of people. Regardless of your silver bullet, I will not follow in the procession. "Most patterns"? Which are you referring to? They're used throughout the .NET Framework, from factories and adapters to decorators. Just my favourite, the memento, isn't included (afaik, which doesn't mean much). A pattern is simply a formalized piece of code that solves a problem. You have a list of those in your intellisense, don't you? Those snippets are formalized pieces of code that follow a specific pattern and that have a name. Now how does one take one of those templated pieces of code and make a holy grail of it? Is it some consultant, yammering to implement an event-receiver in C#? Code needs to be kissable clean; no patterns "just" to show of that you know something, the simplest solution is always the preferred one. But please, do follow the pattern of wrapping your connections and commands in a using-clause, do use parameterized queries, and please, use the factory-method that is included in the connection object to create your command. It saves a lot of time when rewriting to another provider. ..maybe I should just put my rambling in an article, as a lot of devs that I respect are not too fond of patterns for some weird reason. Tell me, do you vary your code to show a form, or does that happen to be another unnamed pattern that you repeat? :rolleyes:

                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                      L N B K 4 Replies Last reply
                      0
                      • OriginalGriffO OriginalGriff

                        I use this when the instances are going to be resource heavy - maybe have a couple of images in them - and / or I want one example of each instance through the whole system. So I have a private constructor, a static Dictionary containing all created instances, and a static method which fetches the instance:

                        private static Dictionary all = new Dictionary();
                        private MyClass(string name, List data )
                        {
                        ...
                        all.Add(name, this);
                        }
                        public static MyClass Get(string name, List data)
                        {
                        if (all.ContainsKey(name)) return all[name];
                        return new MyClass(name, data);
                        }

                        And it works really well. But ... is that a pattern? I hope not, I might have to stop using it ... :~

                        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                        N Offline
                        N Offline
                        Nagy Vilmos
                        wrote on last edited by
                        #14

                        The only pattern worth using is GIWAGO - 'Get It Working And Get Out!' :laugh:

                        veni bibi saltavi

                        1 Reply Last reply
                        0
                        • OriginalGriffO OriginalGriff

                          I use this when the instances are going to be resource heavy - maybe have a couple of images in them - and / or I want one example of each instance through the whole system. So I have a private constructor, a static Dictionary containing all created instances, and a static method which fetches the instance:

                          private static Dictionary all = new Dictionary();
                          private MyClass(string name, List data )
                          {
                          ...
                          all.Add(name, this);
                          }
                          public static MyClass Get(string name, List data)
                          {
                          if (all.ContainsKey(name)) return all[name];
                          return new MyClass(name, data);
                          }

                          And it works really well. But ... is that a pattern? I hope not, I might have to stop using it ... :~

                          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                          D Offline
                          D Offline
                          Duncan Edwards Jones
                          wrote on last edited by
                          #15

                          It is the Tinder pattern. (A collection of singletons)

                          OriginalGriffO J B 3 Replies Last reply
                          0
                          • L Lost User

                            OriginalGriff wrote:

                            Because most patterns are a waste of time, but worshipped as the One True Holy Grail of Computing by those that learn it. And then force all applications they write to fit that pattern regardless of the appropriateness.

                            ..you are interacting with the wrong kind of people. Regardless of your silver bullet, I will not follow in the procession. "Most patterns"? Which are you referring to? They're used throughout the .NET Framework, from factories and adapters to decorators. Just my favourite, the memento, isn't included (afaik, which doesn't mean much). A pattern is simply a formalized piece of code that solves a problem. You have a list of those in your intellisense, don't you? Those snippets are formalized pieces of code that follow a specific pattern and that have a name. Now how does one take one of those templated pieces of code and make a holy grail of it? Is it some consultant, yammering to implement an event-receiver in C#? Code needs to be kissable clean; no patterns "just" to show of that you know something, the simplest solution is always the preferred one. But please, do follow the pattern of wrapping your connections and commands in a using-clause, do use parameterized queries, and please, use the factory-method that is included in the connection object to create your command. It saves a lot of time when rewriting to another provider. ..maybe I should just put my rambling in an article, as a lot of devs that I respect are not too fond of patterns for some weird reason. Tell me, do you vary your code to show a form, or does that happen to be another unnamed pattern that you repeat? :rolleyes:

                            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #16

                            Eddy Vluggen wrote:

                            But please, do follow the pattern of wrapping your connections and commands in a using-clause, do use parameterized queries, and please, use the factory-method that is included in the connection object to create your command. It saves a lot of time when rewriting to another provider.

                            Can't tell if you're being sarcastic because there's not much there I agree with (except maybe the parametrised queries, even then ...) Using older dated systems/databases/external devices some of that is not even possible let alone sensible. But this is not really the correct forum for that and I'm off to bed anyway.

                            Installing Signature... Do not switch off your computer.

                            1 Reply Last reply
                            0
                            • D Duncan Edwards Jones

                              It is the Tinder pattern. (A collection of singletons)

                              OriginalGriffO Offline
                              OriginalGriffO Offline
                              OriginalGriff
                              wrote on last edited by
                              #17

                              Swipe left! Swipe left!

                              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                              1 Reply Last reply
                              0
                              • OriginalGriffO OriginalGriff

                                I admit I googled ... mostly Beer companies, which may be appropriate.

                                Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                                J Offline
                                J Offline
                                Jorgen Andersson
                                wrote on last edited by
                                #18

                                Success. :-D

                                Wrong is evil and must be defeated. - Jeff Ello

                                1 Reply Last reply
                                0
                                • OriginalGriffO OriginalGriff

                                  :laugh: That's actually a pretty good name for it, considering!

                                  Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                                  J Offline
                                  J Offline
                                  Jorgen Andersson
                                  wrote on last edited by
                                  #19

                                  Joke aside, I believe there is a pattern called the flyweight pattern that is fitting the description.

                                  Wrong is evil and must be defeated. - Jeff Ello

                                  1 Reply Last reply
                                  0
                                  • L Lost User

                                    OriginalGriff wrote:

                                    Because most patterns are a waste of time, but worshipped as the One True Holy Grail of Computing by those that learn it. And then force all applications they write to fit that pattern regardless of the appropriateness.

                                    ..you are interacting with the wrong kind of people. Regardless of your silver bullet, I will not follow in the procession. "Most patterns"? Which are you referring to? They're used throughout the .NET Framework, from factories and adapters to decorators. Just my favourite, the memento, isn't included (afaik, which doesn't mean much). A pattern is simply a formalized piece of code that solves a problem. You have a list of those in your intellisense, don't you? Those snippets are formalized pieces of code that follow a specific pattern and that have a name. Now how does one take one of those templated pieces of code and make a holy grail of it? Is it some consultant, yammering to implement an event-receiver in C#? Code needs to be kissable clean; no patterns "just" to show of that you know something, the simplest solution is always the preferred one. But please, do follow the pattern of wrapping your connections and commands in a using-clause, do use parameterized queries, and please, use the factory-method that is included in the connection object to create your command. It saves a lot of time when rewriting to another provider. ..maybe I should just put my rambling in an article, as a lot of devs that I respect are not too fond of patterns for some weird reason. Tell me, do you vary your code to show a form, or does that happen to be another unnamed pattern that you repeat? :rolleyes:

                                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                                    N Offline
                                    N Offline
                                    Nelek
                                    wrote on last edited by
                                    #20

                                    Eddy Vluggen wrote:

                                    maybe I should just put my rambling in an article,

                                    Why not? Do it... I really think it might bring a nice debate in the board

                                    M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                                    1 Reply Last reply
                                    0
                                    • OriginalGriffO OriginalGriff

                                      I use this when the instances are going to be resource heavy - maybe have a couple of images in them - and / or I want one example of each instance through the whole system. So I have a private constructor, a static Dictionary containing all created instances, and a static method which fetches the instance:

                                      private static Dictionary all = new Dictionary();
                                      private MyClass(string name, List data )
                                      {
                                      ...
                                      all.Add(name, this);
                                      }
                                      public static MyClass Get(string name, List data)
                                      {
                                      if (all.ContainsKey(name)) return all[name];
                                      return new MyClass(name, data);
                                      }

                                      And it works really well. But ... is that a pattern? I hope not, I might have to stop using it ... :~

                                      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                                      M Offline
                                      M Offline
                                      Marc Clifton
                                      wrote on last edited by
                                      #21

                                      Yes, it's called the "static cling" pattern as nothing put into the dictionary ever gets garbage collected. ;)

                                      Latest Article - Class-less Coding - Minimalist C# and Why F# and Function Programming Has Some Advantages Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                                      C B 2 Replies Last reply
                                      0
                                      • D Duncan Edwards Jones

                                        It is the Tinder pattern. (A collection of singletons)

                                        J Offline
                                        J Offline
                                        Jeremy Falcon
                                        wrote on last edited by
                                        #22

                                        Boom! You sir, have won the Internet today. :laugh:

                                        Jeremy Falcon

                                        1 Reply Last reply
                                        0
                                        • OriginalGriffO OriginalGriff

                                          I use this when the instances are going to be resource heavy - maybe have a couple of images in them - and / or I want one example of each instance through the whole system. So I have a private constructor, a static Dictionary containing all created instances, and a static method which fetches the instance:

                                          private static Dictionary all = new Dictionary();
                                          private MyClass(string name, List data )
                                          {
                                          ...
                                          all.Add(name, this);
                                          }
                                          public static MyClass Get(string name, List data)
                                          {
                                          if (all.ContainsKey(name)) return all[name];
                                          return new MyClass(name, data);
                                          }

                                          And it works really well. But ... is that a pattern? I hope not, I might have to stop using it ... :~

                                          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                                          L Offline
                                          L Offline
                                          Lost User
                                          wrote on last edited by
                                          #23

                                          OriginalGriff wrote:

                                          So I have a private constructor, a static Dictionary containing all created instances, and a static method which fetches the instance:

                                          I only see a downside

                                          you create an "instance" and fill it with data // no problems
                                          ...
                                          later fetch your "instanse" and do the work // ...wow, that went pretty quick

                                          all you've done is taken away the ability of the code editor/compiler to check the item exists and built in another opportunity for a hard to find run-time problem. (if you missed it check the spelling, because the compiler wont do that for you.) and the upside isn't there, a separately declared list left empty takes few resoures.

                                          Installing Signature... Do not switch off your computer.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups