design-patterns

Regular Expressions Algorithm

Given a sub-string, is there a way to generate all the possible regular expressions (most restrictive to least restrictive) that would match that sub-string for a given string? For example, say you have a sub-string "orange" and a string "apple banana orange grape". How would I get a list of regexes that match "orange" (I know there wil...

What are the essential elements of a workflow?

Long version: What would be the essential elements/components of a workflow to be implemented in C# (without using any part of WF 3.5 or WF 4)? Note I: I want to implement a master-slave communication where server-side is always passive(slave) and my workflow mainly performs tasks related to such communication scheme. Note II: Since i...

Three Similar APIs - Best Design Pattern?

Hey guys, I'm looking for some thoughts on which design pattern(s) to use for my problem, regardless of language. I am accessing three APIs that have different interfaces and functionality, but are all for the same purpose, returning information to me, in a uniform way, about the same kind of content -- blog authors. Some APIs do exa...

Which programming tools techniques have empowered you most?

I'm curious which programming tools have empowered you as the programmer the most. By empower I essentially mean tools have made complex tasks simpler (both conceptually and implementation wise). I am talking about Objective C and Cocoa primarily, although I suppose this question is rather language independent. For instance, before I di...

Best practice approach to code structure in this situation?

Hey, I have a question regarding code structure, and was wondering what the best practice is or if there was a specific design pattern I should be using. I have an abstract base class BoundingVolume which can have subclasses such as BoundingSphere, BoundingBox, etc. A comparison has to be made between two BoundingVolumes to determine if...

Composite pattern confuses me

I have a few different types of validator classes that i am using at the moment all implementing a validator interface. Occasionally i require combinations of them but usually i need them individually. Does this sound like a good situation to use the composite pattern? ...

Getting out of a procedural mindset

I have been programming (as a job) for around 3-4 months now after having graduated from university studying computing. At university I was taught object orientated programming and I felt I had a good grasp on this until I started working on real problems. I just cant seem to do anything but come up with procedural code for solutions -...

Best practices to partition Model code to logical parts in MVC? Which is the best?

Hi, I'm new to MVC but from what I have learned so far (for example here, by ScottGu) one should aspire to "skinny controllers" rather than "fat" ones. Add to that the fact that views are inherently thin, and you'll get a lot of code in your model. So my question is - How do you partition the code in your model to different logical pa...

What security measures should be taken when creating "change your password" functionality?

I'm adding a "change password" functionality to my webgame http://ninjawars.net , which currently has fixed (and essentially never changing) passwords. I want to avoid making a mess of it, so I'd like to make sure that I have the basic security bases covered. Taking what I can pull from facebook's way of doing things, a few points that...

OOP - Extending DOMElement in PHP with registerNodeClass

registerNodeClass is great for extending the various DOMNode-based DOM classes in PHP, but I need to go one level deeper. I've created an extDOMElement that extends DOMElement. This works great with registerNodeClass, but I would like to have something that works more like this: registerNodeClass("DOMElement->nodeName='XYZ'", 'extDOMXYZ...

Having a class for each table in the database

I'm creating a software for my friends library. For now I have a table in the database for books and movies, but lets say that the user would want to add cds aswell. Then I'd have to let the user create a table in the database for cds. The design so far, is to be having a class for each table in the database, with its fields, and methods...

Is there a framework or pattern for applying filters to data?

The problem: I have some hierarchical data in a Django application that will be passed on through to javascript. Some of this data will need to be filtered out from javascript based on the state of several data classes in the javascript. I need a way of defining the filters in the backend (Django) that will then be applied in javascript...

Design Patterns for the manipulation of search results

Hi, I'm developing an application which makes extensive use of search results, including handling of filters, manual query expansion and annotations. Do you know any related design patterns specifically for this purpose? (the more language independent the better) Have you ever applied any of the classic GoF design patterns for this issu...

Passing Objects between different Windows in a java based tool application

Hi Everyone, I am designing a tool application that requires different windows passing objects not just messages at run time. I am also new to design patterns. However, since this application is not designed for network problems I was wondering if there are/is any design patterns such as router pattern for making this communications. R...

Why this is NOT thread safe?

Hi In this code, why has been written "Not thread safe"? Thank you class Singleton { private static Singleton _instance; // Constructor is 'protected' protected Singleton() { } public static Singleton Instance() { // Uses lazy initialization. // **Note: this is not thread safe.** if (_instance == null) { ...

Understanding some of the design patterns(GOF) is difficult.How do I understand them ?

Hi You know, some of the GOF patterns like Singleton or prototype are pretty simple. But some of them like factory method is clearly complicated. What is your advise for understanding them quickly? Thank you ...

Any pattern for "one class per one action/page"?

Hello, MVC is a really good pattern, but sometimes it is really boring to put everything into Controller's methods. Controller is constantly growing and it takes time to get rid of thousands of code lines. Some people highly recommends to put as much as possible into Model, but I prefer to keep Model clean (I don't put controller orient...

Design pattern for an email notification service which monitors workflow/state

I'm sorry this question is going to be a bit vague because I'm not entirely sure what I'm looking for. Basically in my (Asp.net MVC) web app I have some basic (manually coded) workflow triggered by my various user inputs. I need to send email configurable notifications when certain events happen. For example, there is an update status...

When to use which pattern?

Hello, As a junior developper, i'm a bit confused about some design patterns. Sometimes, i just don't know which to use in which context. For exemple, on creational patterns, i don't really know when to use: Factory Prototype Builder Actually, i see some differences; but i also see that you can use multiple solutions like: Callin...

Design Patterns... Where to start? (Some real-world samples)

I'm kind of new to the design patterns concept. C# is my primary programming language. (I use VB from time to time). I don't want to write sloppy code which is inflexible, not extendable and buggy. Whenever I see a design pattern in action, I enjoy the logic behind it and understand it well, But unfortunately, I'm having trouble implemen...