design-patterns

What is the best practise for providing a method/class/component that supports cancellation?

How do you design a method/class that should support cancellation of the operation? I realized that I never do that in a consistent manner and I want to change that. Some of the things I have used: a boolean property on the class IsCancelled that I synchronize internally. sometimes I have a CanCancel property if the operation cannot ...

Can anybody explain the concept of pluggable adapter to me with good example?

Can anybody explain the concept of pluggable adapter to me with good example? ...

Singleton instance declared as static variable of GetInstance method

I've seen implementations of Singleton patterns where instance variable was declared as static variable in GetInstance method. Like this: SomeBaseClass &SomeClass::GetInstance() { static SomeClass instance; return instance; } I see following positive sides of this approach: The code is simpler, because it's compiler who respon...

Design patterns to avoid

A lot of people seem to agree, that the Singleton pattern has a number of drawbacks and some even suggest avoiding the pattern entirely. There's an excellent discussion here. Please direct any comments about the Singleton pattern to that question. My question: Are there other design patterns, that should be avoided or used with great c...

Are there cases where a singleton is the best option?

There is a lot of discussion on this site about why singletons should be avoided but are there any cases where a singleton makes sense and is the best option? An example where I think that a singleton is the best option is when implementing an Identity Map where you need to keep track of all models that have already been loaded from the...

Can a piece of code, if reusable and applicable to different contexts be classified a pattern?

What constitutes a pattern ? If i have a template/code that is reusable and can be applied to other similar situations, can it be called a pattern ? The following is what i have created. It is a binary approach to handling conditional constructs. I have a field in a table that is composite i.e. it comprises of 3 or more other sub-fields...

Object-level transaction management pattern

I'm trying to find out the best way to handle transactions at object level (not database level). Short example: 4 objects A, B, C and D. A starts a transaction and calls methods in B and C. Whithin this transaction C is also calling D. The methods being called aren't supposed to always participate in this transaction, but can be called a...

Most binary combinations from 4 bits - with each bit able to change state only once

I have 4 binary bits Bit 3 Bit 2 Bit 1 Bit 0 Normally the answer is simple: 2^4, or 16 different combinations; and it would looks something like the following: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 However, The LSB (Bit 0) changes state every iteration I need an algorithm where the state ...

Handling Dialogs in WPF with MVVM

In the MVVM pattern for WPF, handling dialogs is one of the more complex operations. As your view model does not know anything about the view, dialog communication can be interesting. I can expose an ICommand that when the view invokes it, a dialog can appear. Does anyone know of a good way to handle results from dialogs? I am speakin...

Difference between three tier vs. n-tier

I just came across the following sentence: As the industry has moved from a three tier model to n-tier models, the object relational impedance mismatch has become more prevalent. But I can't find a concise explanation of the difference between three tier and n-tier. I know what three tier is, and I assume n-tier just adds one or ...

Business Logic Layer and Data Access layer: circular dependency

Hello, I’m having a little Architecture problem. In my project I have a Business Logic Layer (BLL) that contains all my business rules, models and OO API for the interface. Each object has static methods like getById that return an instance of said object. Each object also has methods like save and, delete. This is very straightforward ...

Quality Without A Name examples?

The Quality Without A Name is Christopher Alexander's term for an attractive feature which is not quite "beauty" or "comfort" or "aliveness" or any other term. But which we can recognise in buildings. For those influenced most by Alexander's pattern-language thinking, we probably think we can see it in software too : either for end user...

Where to put the GetObjectColletion Methods?

An app has a Foo class that is a concrete class with all business logic and behaviour properly defined. That said, one need to get the collection of all the Foos that are persisted at this app. Where should this "IEnumerable GetFoos()" method be placed? Not at the Foo class itself, right? ...

Choose which class to instantiate c#

Hi All, what i want to do is select the appropriate class to instantiate based on parenthesis passed in. Currently what i have are two classes (ClassA and ClassB) and to call these im using 2 methods depending on the parenthesis. What i would like to achieve is to use just one method to instantiate either ClassA or ClassB based on the ...

What is the difference between the bridge pattern and the strategy pattern?

I tried to read many articles on dofactory, wikipedia and many sites. I have no idea what the difference is between them. I know both of them decouple an abstraction from its implementation and can change implementation at run time. But I still don't know in which situation I should use strategy or in which situation I should use brid...

Best way to build a Plugin system with Java

How would you implement a Plugin-system for your Java application? Is it possible to have an easy to use (for the developer) system which achieves the following: Users put their plugins into a subdirectory of the app The Plugin can provide a configuration screen If you use a framework, is the license compatible with commercial develop...

Designing services and operations in WCF.

Hi, I would appreciate some guidance on modelling services and operations in WCF. I have a series of business domains, each with bespoke methods that I want to able to use over WCF. I guess an OO view would be something like: interface IBusinessDomain1 { MyClass1 Method1(...) MyClass2 Method2(...) } interface IBusinessDomain2...

Constructing an Object from a Class Reference

I have a method which constructs an object, calls an Execute method, and frees the object. The type of object is determined by a TClass descendant passed into the method. Note this is Delphi for Win32 I am talking about, not .NET. Edit: I should point out that this is Delphi 2006, as it has been noted in answers below that in future ver...

When are design patterns the problem instead of the solution?

I’ve never worked on software where I needed to use design patterns. According to Paul Graham’s Revenge of the Nerds essay, design patterns are a sign of not enough abstraction. To quote him directly, “For example, in the OO world you hear a good deal about "patterns". I wonder if these patterns are not sometimes evidence of case (c), ...

Can anybody give me an example of overused design patterns?

I've been hearing and reading about cases when people had come across cases of overused design patterns. Ok, missused design patterns are understandable phenomenon. What does it actually mean overused design patterns? Do you have any examples and why do you think there are too many patterns? ...