ternary operators are useful for simple one liner statement.
i saw some ternary operator being abused in a php code it was hell, tracing it lol
i use watch if im debugging multiple functions, that are using a common variable name inside.
another design pattern i see useful is a class factory.Code:func1() { x = blah blah } func2() { x = blah blah 2 }
i dont want to talk about it cuz google does a better job LOL.
singleton is a pattern used to insure you only have 1 instance of that class for the entire lifespan of the assembly.
as for the class factory or factory design pattern.
Factory method pattern - Wikipedia, the free encyclopedia
Nope. A factory is an object that instantiates various classes, although the factory itself can be implemented as a singleton.
Analogy: a singleton is like a static variable in C. All instances of a singleton would refer to only one object. It's like a global variable in C (in fact, most people use singletons as replacements for globals).
Problem: A thread instantiate a singleton, while it's not done instantiating, another thread instantiate the same singleton class. Now they are two instances.
So how do you ensure single instance in a Singleton in a multi-threaded environment?![]()
is this with respect to JAVA?
in C++/C# we have a volatile keyword: (can be useful across multiple domain under multithreaded application.)
The volatile keyword indicates that a field can be modified in the program by something such as the operating system, the hardware, or a concurrently executing thread. The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock statement to serialize access. Using the volatile modifier ensures that one thread retrieves the most up-to-date value written by another thread.
if single domain only, locking/synchronization with static initialization approach is enough I guess.
there are variety of threading under managed/unmanaged world... If the implementation uses a ThreadPool under managed world, one can apply delay/sleep under Running State of the thread.
Similar Threads |
|