I'm reading a c# book that describes the SyncRoot pattern. It shows
void doThis()
{
lock(this){ ... }
}
void doThat()
{
lock(this){ ... }
}
and compares to the SyncRoot pattern:
object syncRoot = new object();
void doThis()
{
lock(syncRoot ){ ... }
}
void doThat()
{
lock(syncRoot){ ... }
}
However, I don't really...
I'm not sure which of these two "patterns" is the best. Currently I use option A (in conjunction with a provider for implementing persistence), but I'm now erring towards B, especially in light of unit tests being able to use the "dependency injection" model.
Option A:
class ClassA
{
ClassA() { }
Save();
static List<ClassA> G...
In general, what is the maximum number of parameters a class constructor should accept? I'm developing a class that requires a lot of initialization data (currently 10 parameters). However, a constructor with 10 parameters doesn't feel right. That leads me to believe I should create a getter/setter for each piece of data. Unfortunately, ...
I have the following class:
class User {
public function setName($value) { ... }
public function setEmailAddress($value) { ... }
public function setUsername($value) { ... }
public function getName() { ... }
public function getEmailAddress() { ... }
public function getUsername() { ... }
public function isGroupAdministrato...
Is there any advantage for using visitor pattern in a recursive scenario? If so can you demonstrate it programmatically?
...
I've been going through Head First Design Patterns (just came in recently) and I was reading about the strategy pattern, and it occurred to me that it might be a great way to implement a common way of calculating taxes etc. on all of the particular objects I use at work, but I had a question about it.
Here's what I was thinking:
public...
In Java, it is very easy to code the following design:
public abstract class Pizza {
public static final Pizza.NULL = new Pizza() {
/* "null" implementations */
}
/* actual/abstract implmentations */
}
What is the preferred method to attain the same efficient scenario in Objective-C? I have been unable to find any...
I was avoiding writing what may seem like another thread on .net arch/n-tier architecture, but bear with me.
I, hopefully like others still am not 100% satisfied or clear on the best approach to take given today's trends and new emerging technologies when it comes to selecting an architecture to use for enterprise applications.
I suppo...
How can I implement the Producer/Consumer patterns in C# using Events and Delegates? What do I need to keep an eye out for when it comes to resources when using these design patterns? Are there any edge cases I need to be aware of?
...
Duplicate
On Design Patterns: When to use the Singleton
class Singleton
{
private static Singleton instance;
private Singleton() {}
public static Singleton Instance
{
get
{
if (instance == null)
instance = new Singleton();
return insta...
Smack's XMPPConnection implements an event-driven manner of receiving XMPP responses from a jabber server. The method [addPacketListener][1] allows you specify your own custom listener. I'm maintaining code in which one PacketListener handles all types of incoming messages. In the interest of improving the design, (with a nod to the Sing...
Here is my problem.
I am trying to write a small simple game engine (I'm doing it in order to improve my design skills) . I'm having a Scene Object which hold everything the rendering API need in order to render it.
Naturally , I would like my scene to be immune to future changes , meaning future changes to it will not have to break it...
I'd like to pair a Model with it's View through an interface. I want to control when and how often the view is updated. So something like PropertyChangeListener wouldn't work well (where an event is fired after each property is set).
I'm not developing for a specific GUI framework. The goal here is the ability to swap out different GUI ...
I need to write handlers for several different case types (in Python). The interface for all this types are the same, but the handling logic is different.
One option would be defining a common class that receives the particular handler type as one of the __init__ parameters:
class Handler:
def __init__ (self, handlerType):
...
I was exploring about Extensible object pattern using (IExtension, IExtensibleObject) interfaces in C#,
I came with a very simple example to convert dates to UTC from local and vice-versa:
public class BaseObject : IExtensibleObject<BaseObject>
{
private DateTime _startDate;
private ExtensionCollection<BaseObject> _...
Other than implementation details, are DDD aggregates similar to GoF's facade ?
...
Basically I have an entity (called Session) which will provide many different Services. Each service can be selectively turned ON or OFF by the user (signin or signout). I am not sure what's the best design to represent this. See UML
From a programming use case perspective, the interactions with a Session instance:
Session session = ne...
I'm writing a C# .NET module and I would like to use the provider pattern.
If my code is running on a web server, I have access to System.Web.Configuration and can call ProvidersHelper to load an appropriate provider as determined by the web.config data.
If my code is running in a stand-alone environment, I won't have access to this...
Hello,
I have built a system that conforms to the mvc pattern in PHP. The controllers and actions are part of the urls in my application. So I have:
www.example.com/controller/action/
So now I am looking for a way to pass on variables. For forms I just use the post method, but sometimes I would just like to link to a different page an...
Ok, suppose I have Ruby program to read version control log files and do something with the data. (I don't, but the situation is analogous, and I have fun with these analogies). Let's suppose right now I want to support Bazaar and Git. Let's suppose the program will be executed with some kind of argument indicating which version control ...