design-patterns

configuring "plumbing" at runtime

This is kind of a design-patterns question in Java. I am designing a java .jar file to act as a frameworks for managing and processing a certain form of data. I want the end user to be able to dictate the "plumbing" configuration, within certain constraints, in a certain way. The pieces are producers and/or consumers, and I know how to ...

How to implement search features in ASP.NET MVC applications

I can imagine many ways of implemeting search features in an ASP.NET MVC application but since I can't find much documentation I was wondering if you have any common pattern, technology or common approach to implement search features in a ASP.NET MVC application (similar to stackoverflow). Some technologies that I have in mind are: SQL...

NSThread and object retain count issue

I want to be able to call an object's method on a new thread; but, I am confused about how to manage retain counts (or even if it is an issue). In a non-threaded scenario, I would do this: MyObject *newObject = [[MyObject alloc] init]; [newObject doSomething]; [newObject release]; In this scenario, everything's fine. However, my ques...

Sending arbitrary data through several functions

While making a state system that follows the state design pattern (which is working quite well so far) and I am now wondering if there is a way to send arbitrary data to this system. I was thinking that this might be possible using a Stimulus class. The system itself is composited into another object that can respond to the stimuli, an...

Implementing a Factory that uses Specifications to determine which type of object to create

This is mainly a thought experiment. So this all is sample code. My goal was to use the specification pattern to eliminate giant blocks of conditional code inside a factory. So with this sample I have a StatusData object that I want to get an implementation of IStatusUpdate that is appropriate for for it. I have the following set of tes...

What anti patterns do you use even though you know you shouldn't?

Am I the only one that sometimes take the seemingly easy, but wrong, way out of certain design situations? I'll admit I've made my share of questionable Singleton objects. Besides that, I've been known to make a God object or two to make things seem easier. Do you ever use an anti-pattern even though you know you shouldn't? ...

UI specific properties on an object

Lets assume I have a simple class called Category, with properties Id, Name. I want to show these as a menu in the UI. But the display logic is also affected by a third property, IsSelected, that I have to take account when I'm rendering the menu. There are plenty of different ways to achieve this, for instance by inheriting or using pa...

Design patterns and algorithms for applying rules to facts

I am in the midst of trying to nail down requirements from a client for a pricing engine in a retail environment. We have defined the pricing engine as operating on a set of pricing rules that establishes new price points for purchased items based on existing items already in the shopping cart. A simple price rule might be GET A SHIRT 4...

What is the advantage to have all my classes instantiated only through the Factory DP?

What is the advantage to have all my classes instantiated only through the Factory DP? As far as know a Factory is good when you have to choose from a list of similar objects to perform some task,let's say like translations classes (english-> franch, arab->hebrew ...) But when you have really one possible option, no reason to obscure/ab...

Transactions in the Repository Pattern

How do I encapsulate the saving of more than one entity in a transactional manner using the repository pattern? For example, what if I wanted to add an order and update the customer status based on that order creation, but only do so if the order completed successfully? Keep in mind that for this example, orders are not a collection in...

Is there a pattern for propagating details of both errors and warnings?

Is there a common pattern for propagating details of both errors and warnings? By errors I mean serious problems that should cause the flow of code to stop. By warnings I mean issues that merit informing the user of a problem, but are too trivial to stop program flow. I currently use exceptions to deal with hard errors, and the Python l...

how do you folks handle complex state situations where order of operations is important?

Hello, I'm getting in to a situation where I have several interacting widgets (on a web UI), all of whom can be in multiple different states, and whose behavior depends on others the others. I'm running in to situations where, for example, a set of data gets sorted twice, or the data gets displayed before it's sorted, rather than the oth...

How can I port this Java code to C#?

I am looking at a pattern implemented in Java and have some questions about how it aligns to (can be ported to) C#. Java: class Foo { private Class someClass; ... } class Bar { private Field some Field; } First, Class stores an instance of a domain object. It looks like Java exposes reflection methods on the type which ...

Should business logic layer implement authorization & authentication?

I have a business logic layer (the "repository") which is exposed as a set of .NET interfaces backed by swappable concrete implementations. Originally I had this business layer implement authentication and authorization (authn/authz), meaning I had interfaces such as IUserIdentity and IUserRole, and all methods that accessed sensitive d...

Factory pattern

I've been trying to create a factory (in Java) that prohibits subclassing of the factory product and prevents the concrete factories from being used by anyone except the abstract factory. What do you think of this... class Client { public static void main(String[] args) { Animal animal = Animal.create(Lion.class); ...

How to start recognizing design patterns as you are programming?

I have general academic knowledge of the various design patterns that are discussed in GoF and Head First Design Patterns, but I have a difficult time applying them to the code that I am writing. A goal for me this year is to be able to recognize design patterns that are emerging from the code that I write. Obviously this comes with exp...

What are the options for finding nodes when using the composite pattern?

Apart from recursively querying each node, are there any other options for searching for a node given some identifier? ...

What are some design patterns for doing version control of an object?

What are some design patterns for keeping a history of an object as it changes. I don't need anything as heavy duty as event sourcing, just the ability to save past versions when a specific event happens (in this case when a print form button is pressed). ...

How bad is it to put javascript outside of the header?

The question pretty much already says everything. I'm starting to add some features to my weekend project. It's a small app for me and a couple of friends, as we're exchange students it's kinda useful for us. But the thing is the following, I'm doing this in php and structuring everything with includes so i can get the code separated. ...

Force singleton pattern in subclasses.

I would like to force subclasses to implement the singleton pattern. I originally thought of having an abstract static property in the parent class, but upon closer though, that didn't make sense (abstract requires and instance). Next, I thought of having an interface with a static property, but that also doesn't make sense (interfaces...