design-patterns

What ideas from other fields are of use to programmers

The idea of patterns originated in architecture back in 1977 The equivalent of TDD was being used in manufacturing industry as part of Just In Time and Total Quality back in the 1980s Paul Graham has famously linked Hackers and Painters My question is this, what are your favourite ideas and techniques that we can use from other fields...

UnitOfWork Implementation

Hello everybody, probably I'm too n00b to understand this, but I was reading the Gabriel Schenker http://nhforge.org/wikis/patternsandpractices/nhibernate-and-the-unit-of-work-pattern.aspx UnitOfWork implementation and I really cannot get the point. Why does the UnitOfWorkImplementor.Dispose need to forward the dispose to the UnitOfWork...

How should one class request info from another one?

I am working on a VB.NET batch PDF exporting program for CAD drawings. The programs runs fine, but the architecture is a mess. Basically, one big function takes the entire process from start to finish. I would like to make a separate class, or several, to do the exporting work. Here's the problem: Sometimes the pdf file which will be c...

Convention for Javascript Domain Model Objects

Hi all, If I have to create a domain model object in C# I might do something like this: public class Person { Public string Name { get; set; } Public string Gender { get; set; } Public int Age { get; set; } } In Javascript, what is the convention for defining such objects? I'm thinking something like this: NAMESPACE.Pers...

Where should my models live? Web tier or Data tier? (MVC + NHibernate)

I am setting up an n-tier application with MVC, Ninject, and NHibernate (my first using these technologies). For clarity's sake, the tiers are a "Data" tier, a "Services" tier, and a "Web" tier (all are separate projects). With MVC, you have your models that are in the "Models" folder. It seems necessary to put my models here to create...

polymorphic properties design pattern

I have this big polymorphic object hierarchy, and I want to expose these objects to another language using primitive types. I'm thinking my base object will have a dictionary of properties (C++), and each sublcass down the hierarchy will add properties or modify properties, and then when i forward to the other language, i don't need any...

Useful mini patterns (not design patterns)

My most used mini pattern is: VideoLookup = new ArrayList { new ArrayList { buttonVideo1, "Video01.flv" }, new ArrayList { buttonVideo2, "Video02.flv" }, new ArrayList { buttonVideo3, "Video03.flv" }, new ArrayList { buttonVideo4, "Video04.flv...

Parsing huge data with c++

In my job, i need to parse different kind of data files from different data sources.Sometimes i parse them by writing directly c++ code (with the help of qt and boost:D), sometimes manually with a helper program. I must note that data types are so different from each other it is so hard to create common a interface for all of them. But i...

Concrete class specific methods

I have an interesting problem. Consider this class hierachy: class Base { public: virtual float GetMember( void ) const =0; virtual void SetMember( float p ) =0; }; class ConcreteFoo : public Base { public: ConcreteFoo( "foo specific stuff here" ); virtual float GetMember( void ) const; virtual void SetMember( float p ...

Can you use a string to instantiate a class in python?

I'm using a builder pattern to seperate a bunch of different configuration possibilities. Basically, I have a bunch of classes that are named an ID (something like ID12345). These all inherit from the base builder class. In my script, I need to instantiate an instance for each class (about 50) every time this app runs. So, I'm trying to ...

Different ways to implement 'dirty'-flag functionality

Almost every programmer did it once in his life: setting some flag if a variable's value changed. There's always lots of properties and you want to keep track if something changed in any property in a specific property or in some set of properties I'm interested in different ways to implement the "dirty-flag" functionality for the a...

OO Design Question

What do you do when you notice that an app has a lot of classes, but the classes are not really intantiable objects but rather a grouping of common functions? Example: Class Point { calculatePoints(something) {} calculatePointsAnotherWay(something) {} } ...

Domain Driven Design and the role of the factory class

I'am unclear as to what the roles and responsibility of the factory class is. I know enough that the factory class should be resposible for the creation of domain objects (aggregate root) along with its associated entities and value objects. But what is not clear to me is where the factory "layer" lies with a DDD architecture? Should t...

What are the most overused design examples? Provide better examples if you have them.

When given an example of refactoring, I'm tired of seeing a Data Access Layer with string literals for connection strings being replaced by IConnectionStringProvider. eg: public DataSet GetCustomers() { string connectionString = "SQLClient;Blah;Blah"; using(SqlConnection conn = new SqlConnection(connectionString)) ... to...

Name this pattern

Often seen it and often used it, wonder if it has a name? C# version: public class Register { protected Register() { Register.registry.Add(this); } public static ReadOnlyCollection<Register> Instances { get { return new ReadOnlyCollection<Register>(registry); } } private static List<Register>...

What versioning design pattern would you recommend

I have a requirement to build 'versioning' into an application and was wondering how best to approach it. I have this general pattern: Model A has many B's Where on update the attributes of A need to be versioned and its associated objects (B's) also need to be versioned. So the application will display the current version of A, but ...

Dependency Injection vs Factory Pattern

Most of the examples quoted for usage of Dependency Injection, we can solve using the factory pattern as well. Looks like when it comes to usage/design the difference between dependency injection and factory is blurred or thin. Once someone told me that its how you use it that makes a difference! I once used StructureMap a DI containe...

What's the difference between an Algorithm and a Design Pattern

I was searching for "Undo/Redo algorithms" and found something marked as a duplicate, but the duplicate was a request for a "Undo Design Pattern". I'd really like an algorithm for this. I don't think I necessarily need a design pattern. Is there a fundamental difference between "Design Pattern" and "Algorithm" or is it OK that someon...

Examples of great software design and implementation

I hope this isn't a duplicate... What is the most solidly designed and implemented software system/framework/application that you've come across? It seems like TDD, SOLID principles, OO design patterns, and things like that can be easily theorized on podcasts and blogs using really simple examples, but it's hard to imagine developing ...

Can the Diamond Problem be really solved?

A typical problem in OO programming is the diamond problem. I have parent class A with two sub-classes B and C. A has an abstract method, B and C implement it. Now I have a sub-class D, that inherits of B and C. The diamond problem is now, what implementation shall D use, the one of B or the one of C? People claim Java knows no diamond ...