|
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!
|
|
|
|
|
Seems like an Appalachian version of DI, just missing a banjo duel
But fortunately we have the nanny-state politicians who can step in to protect us poor stupid consumers, most of whom would not know a JVM from a frozen chicken. Bruce Pierson Because programming is an art, not a science. Marc Clifton I gave up when I couldn't spell "egg". Justine Allen
|
|
|
|
|
Hmm. I don't see anything wrong with it, other than the name "all " for the container, which isn't terribly descriptive.
I've used similar "patterns", where constructors and destructors maintain global constructs as a side effect. The global constructs usually simplify finding one of the instances in some way, or in accessing the entire collection of 'live' instances. In some cases I also use them for orderly shutdowns, to insure that all instances get destroyed properly.
For what it's worth, I've never read the GoF Patterns book.
Software Zen: delete this;
|
|
|
|
|
Shoulda used a concurrent dictionary...
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
OriginalGriff wrote: And it works really well. But ... is that a pattern?
Yes. Multiton. Been around a long time.
Multiton pattern - Wikipedia[^]
The general idea is a Singleton per 'context' where the definition of the context is up the implementation.
|
|
|
|
|
A cunning way of asking a programming question in the Lounge!
The all field should be readonly , since you never replace it.
You should probably specify an explicit StringComparer for the dictionary, to make it more obvious that the key is case-sensitive.
I'd be inclined to move the Add to the static method, and leave the constructor alone. I'd also replace the ContainsKey / indexer pair with a single TryGetValue call:
public static MyClass Get(string name, List<string> data)
{
if (!all.TryGetValue(name, out MyClass instance)
{
instance = new MyClass(name, data);
all.Add(name, instance);
}
return instance;
}
And as Gerry said, if there's any possibility of the method being called by multiple threads, use a ConcurrentDictionary[^] instead:
private static readonly ConcurrentDictionary<string, MyClass> all = new ConcurrentDictionary<string, MyClass>(StringComparer.Ordinal);
public static MyClass Get(string name, List<string> data)
{
return all.GetOrAdd(name, key => new MyClass(key, data));
}
Let's hope your class doesn't contain any unmanaged or disposable resources, since you'd have no way of knowing when to clean them up.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
What are the virtues of a virtual machine?
... such stuff as dreams are made on
|
|
|
|
|
They are virtually limitless.
Arguing with a woman is like reading the Software License Agreement. In the end, you ignore everything and click "I agree".
Anonymous
|
|
|
|
|
What has to do with programming, your question? Virtually nothing!
|
|
|
|
|
What machine? Where is it?
Installing Signature...
Do not switch off your computer.
|
|
|
|
|
They are the main resource for virtual reality of course.
Don't they learn anything in school anymore these days.
|
|
|
|
|
It gives a hope to all developer for a virtual success and money
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|
My pal Will wanted a new machine but couldn't afford one. I told him to "Assume a virtual machine, if you have it not."
|
|
|
|
|
Everyone knows that a virtual machine is virtuous. Even Lancelot used a virtual machine.
|
|
|
|
|
|
The primary virtue of a virtual machine is that it's easy to restore its virtue.
Software Zen: delete this;
|
|
|
|
|
Just wondering, what people think of the specs of the Razer Gaming Laptops for use as development machines?
We're looking for some fold ups and these look pretty strong contenders. Memory and graphics are high up on our needs as our product is highly visual and at the same time data heavy.
veni bibi saltavi
|
|
|
|
|
Nagy Vilmos wrote: Memory and graphics are high up A computer can never have too much memory, nice and well. But what do you need high end graphics for? Are you really all writing graphics engines and blasting out as many high resolution frames per second as you can?
Nagy Vilmos wrote: highly visual and at the same time data heavy. That sounds more like drawing graphs in some reports to impress some old men in suits. Any chipset should render something like that and not start sweating over it.
I have lived with several Zen masters - all of them were cats.
|
|
|
|
|
The UI is painting a lot of graphics and having a good graphics card - maybe not gamer quality, but good - makes it much smoother. With gammer machines, having a good spec means that they're generally good for developmnt.
veni bibi saltavi
|
|
|
|
|
Yep! The "default" graphics that come with most machines is rubbish - shared memory and cheap chipset.
I upgraded mine to a GTX660Ti and Windows is a whole load smoother (as well as not introducing more bottlenecks on the main RAM)
And it plays games as well!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
The most complex game I play is Colossal Adventure
veni bibi saltavi
|
|
|
|
|
Shirley, you mean Colossal Adventure XXIV 3D VR Turbo GTI?
I have lived with several Zen masters - all of them were cats.
|
|
|
|
|
Ha! My old GTX 570 gave smoke signs and just an hour ago the mail man brought me a new GTX 1070! A wonder that the dead 570 really kept working as a standard graphics card until now. A VGA zombie.
I have lived with several Zen masters - all of them were cats.
|
|
|
|
|
Nagy Vilmos wrote: The UI is painting a lot of graphics and having a good graphics card
So the person actually using the app will have an equivalent system also?
|
|
|
|
|
The specs might be OK.
But I prefer an oldstyle large and moveable keyboard, a mouse (don't like those touchpads), and a large monitor for development. So why using a laptop then which is usually more expensive than a comparable desktop system?
|
|
|
|