design-patterns

How do I create a Class using the Singleton Design Pattern in Ruby?

The singleton pattern is a design pattern that is used to restrict instantiation of a class to one object instance. Although I know how to code the singleton pattern in C++ and Java, I was wondering if anyone know how to implement it in Ruby?...

What JavaScript patterns do you use most?

Lately I find myself frequently creating singletons using the module pattern: var singleton = (function(){ var _privateVariable = {}; var _privateMethod = function() {}; return { publicVariable: {}, publicMethod: function() {} } })(); What is/are you favorite pattern/s for maintainable JavaScript? ...

Why all the Active Record hate?

As I learn more and more about OOP, and start to implement various design patterns, I keep coming back to cases where people are hating on Active Record. Often, people say that it doesn't scale well (citing Twitter as their prime example) -- but nobody actually explains why it doesn't scale well; and / or how to achieve the pros of AR w...

What's your favourite way of interacting with DBs from your programming language?

There are numerous ways to connect and interact with the DB layer. In Java, for example, common usages are JDBC calls of raw SQL, object relational mappers, JDBCTemplate (Spring), stored procedures, etc. In your language, which option is your preference and why? When would you consider the others? ...

Unit of Work Pattern in .Net

Does anyone have any concrete examples of a simple Unit of Work pattern in C# or Visual Basic that would handle the following scenario? I'm writing a WinForms application in which a customer can have multiple addresses associated with it. The user can add, edit and delete addresses belonging to the customer before the customer is saved...

Do you know any patterns for GUI programming? (Not patterns on designing GUIs)

I'm looking for patterns that concern coding parts of a GUI. Not as global as MVC, that I'm quite familiar with, but patterns and good ideas and best practices concerning single controls and inputs. Let say I want to make a control that display some objects that may overlap. Now if I click on an object, I need to find out what to do (Ju...

Do you use design patterns?

What's the penetration of design patterns in the real world? Do you use them in your day to day job - discussing how and where to apply them with your coworkers - or do they remain more of an academic concept? Do they actually provide actual value to your job? Or are they just something that people talk about to sound smart? Note: For...

File Parse Design Pattern

Howdy, Does anybody recommend a design pattern for taking a binary data file, parsing parts of it into objects and storing the resultant data into a database? I think a similar pattern could be used for taking an XML or tab-delimited file and parse it into their representative objects. A common data structure would include: (Hea...

Singletons: good design or a crutch?

Singletons are a hotly debated design pattern, so I am interested in what the Stack Overflow community thought about them. Please provide reasons for your opinions, not just "Singletons are for lazy programmers!" Here is a fairly good article on the issue, although it is against the use of Singletons: scientificninja.com: performant-si...

Can you really build a fast word processor with GoF Design Patterns?

The Gang of Four's Design Patterns uses a word processor as an example for at least a few of their patterns, particularly Composite and Flyweight. Other than by using C or C++, could you really use those patterns and the object-oriented overhead they entail to write a high-performing fully featured word processor? I know that Eclipse ...

Transactional Design Pattern

Hi All I have a need to create a "transactional" process using an external API that does not support COM+ or .NET transactions (Sharepoint to be exact) What I need to do is to be able to perform a number of processes in a sequence, but any failure in that sequence means that I will have to manually undo all of the previous steps. In m...

What Are Some Examples of Design Pattern Implementations Using JavaScript?

I'm a moderately skilled programmer using JavaScript but I am no guru. I know you can do some pretty powerful things with it, I just haven't seen much other than fairly basic DOM manipulation. I'm wondering if people could provide some examples of traditional design pattern concepts such as Factory Method, Singleton, etc using JavaScript...

Best book/resource for learning Java design patterns?

I know the MVC design pattern but would be a little unclear about other Java design patterns, so I was just wondering if there's any useful books or other resources you could recommend to get up to speed with these patterns? ...

Beyond design patterns?

For the past 10 years or so there have been a smattering of articles and papers referencing Christopher Alexander's newer work "The Nature of Order" and how it can be applied to software. Unfortunately, the only works I can find are from James Coplien and Richard Gabriel; there is nothing beyond that, at least from my attempts to find s...

What is MVC and what are the advantages of it?

I found What are mvp and mvc and what is the difference but it didn't really answer this question. I've recently started using MVC because it's part of the framework that myself and my work-partner are going to use. We chose it because it looked easy and separated process from display, are there advantages besides this that we don't kno...

Abstract Factory Design Pattern

I'm working on an internal project for my company, and part of the project is to be able to parse various "Tasks" from an XML file into a collection of tasks to be ran later. Because each type of Task has a multitude of different associated fields, I decided it would be best to represent each type of Task with a seperate class. To do t...

Java Singleton vs static - is there a real performance benefit?

I am merging a CVS branch and one of the larger changes is the replacement wherever it occurs of a Singleton pattern with abstract classes that have a static initialisation block and all static methods. Is this something that's worth keeping since it will require merging a lot of conflicts, what sort of situation would I be looking at f...

Using MVP - How to use Events Properly for Testing

I've just started using the MVP pattern in the large ASP.NET application that I'm building (re-building actually) and I am having a hard time figuring out how I should be using Events applied to the view. Say I have 2 drop down lists in a User Control, where one is dependent on the other's value: <%@ Control Language="vb" AutoEventWire...

Where do I use delegates?

What are some real world places that call for delegates? I'm curious what situations or patterns are present where this method is the best solution. No code required. ...

Is there a simple, elegant way to define Singletons in Python?

There seem to be many ways to define Singletons in python. I was wondering if there is a consensus opinion on StackOverflow. ...