I have a horrible feeling I've been using a pattern for years...
-
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!
:-D
Jeremy Falcon
-
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[^]
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!
-
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!
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[^]
-
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!
The only pattern worth using is GIWAGO - 'Get It Working And Get Out!' :laugh:
veni bibi saltavi
-
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!
It is the Tinder pattern. (A collection of singletons)
-
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[^]
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.
-
It is the Tinder pattern. (A collection of singletons)
Swipe left! Swipe left!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
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!
Success. :-D
Wrong is evil and must be defeated. - Jeff Ello
-
: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!
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
-
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[^]
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.
-
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!
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
-
It is the Tinder pattern. (A collection of singletons)
Boom! You sir, have won the Internet today. :laugh:
Jeremy Falcon
-
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!
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 quickall 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.
-
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!
OriginalGriff wrote:
I hope not, I might have to stop using it ... :~
Bullshit! :-) Design patterns were never intended to be the last word and the answer for everything. There is no law against coming up with your very own way of doing something, no matter what some gurus want to have you believe. The SOLID faction would condemn you for breaching the single responsibility principle and using something akin to global variables and singletons. So what? My personal sin is a message broker that I use in almost any UI. When compared to awkward wasteful automatic routing in a large UI tree or fragile code bloating manual routing, having a message broker as a singleton is a blessing. Some object registers with the broker to be notified when a specific message is sent, another object sends the message at some time and the broker looks up all subscribers and calls their event handlers. This is reasonably fast (no searching the entire UI tree) and absolutely unproblematic. The only weak spot is that an object better unregister its subscriptions when it is being destroyed, otherwise the broker may get bogged down servicing dead subscriptions. Yes, global variables or singletons may be problematic, but sometimes you can have all of the benefits without any complications. I would immediately redesign if any complications materialized, but not simply for the purity of some design philosophy's sake. Why throw away something that has proven itself to be useful often enough? But that's just me. I have always been conservative with redesigning and been building libraries, even when that meant to store machine code routines on cassette tapes and manually relocating them into a new program.
I have lived with several Zen masters - all of them were cats.
-
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
Global variables of any flavor have that problem, that's why I would only do something like that for things that remain mostly constant throughout the program's lifetime. Remember the Win32 hInstance parameter? It was passed to WinMain() as a parameter and remained unchanged from then on and you needed it for many Win32 API calls. The four bytes for a global variable were not much of a problem (yes, it was memory that was not cleaned up until the program ended) and it sure beats passing around that value to every window and dialog. When memory hogging is under control, state is not problematic (or even constant), and when I need it all over the place, I will not go through the trouble of routing that object or variable to the remotest parts of the application.
I have lived with several Zen masters - all of them were cats.
-
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!
A behavioral pattern?
Someone's therapist knows all about you!
-
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[^]
Eddy Vluggen wrote:
maybe I should just put my rambling in an article, as a lot of devs that I respect are not too fond of patterns
I am sure I would learn something valuable, if you did !
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it.» Claude Levi-Strauss (Tristes Tropiques, 1955)
-
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!
Interesting, Griff, I've played with some similar patterns. It probably was not your intent to show all of your code, but your mention of "heavy resources" made me wonder if you implement IDisposable, or the newer CLassName~ finalizer thingee.
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it.» Claude Levi-Strauss (Tristes Tropiques, 1955)
-
It is the Tinder pattern. (A collection of singletons)
Duncan Edwards Jones wrote:
the Tinder pattern
That's a very tricky one since you have to implement your own MultiTassking, and MultiBedding.
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it.» Claude Levi-Strauss (Tristes Tropiques, 1955)
-
Interesting, Griff, I've played with some similar patterns. It probably was not your intent to show all of your code, but your mention of "heavy resources" made me wonder if you implement IDisposable, or the newer CLassName~ finalizer thingee.
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it.» Claude Levi-Strauss (Tristes Tropiques, 1955)
IDisposable - and needless to say there are ways to remove items from the
all
collection to prevent things gumming up the garbage collector.Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!