design-patterns

Is this an example of dependency injection?

Is the example below dependency injection with regard to the Worker class? From my reading about the topic over the last few hours becaue the Worker class isn't obtaining the ITool instance from a property setter or constructor it isn't an example of DI? public MainClass { static void Main(string[] args) { ITool someTool = ...

Is there a pattern for this queueing system, and example Java code?

I have a component that I wish to write and it's the kind of thing that feels like a common pattern. I was hoping to find the common name for the pattern if there is one, and examples of how to go about implementing it. I have a service that queues requests and processes them one at a time. I have a number of client threads which make t...

What pattern should I use for using a SAX parser?

<xml> <Office prop1="prop1" prop2="prop2"> <Version major="1" minor="0"/> <Label>MyObjectA</Label> <Active>No</Active> </Office> <Vehicle prop="prop"> <Wheels>4</Wheels> <Brand>Honda</Brand> <Bought>No</Bought> </Vehicle> </xml> My XML is in this format. I am using a SAX parser to parse this file as the size of ...

Pattern to model a business object in Seam framework ?

Hi, I habe been studying Seam framework for a long time. Altough i do not use it at work, i like its approach. It is very interesting. But i have some doubts. After reading Seam in Action book, i think it is not possible you bind more than one parameter to a business method. Something like @Stateless public class BusinessObjectImpl imp...

Seeking iPhone App Architecture Advice: Managing Data

I've built a simple iPhone app that parses data from a remote XML feed, converts the information into objects (they're videos), and displays the videos in a standard table view->detail view->"Play Video" UI. There are hundreds of videos, each with about ten attributes. (The videos are never downloaded, only streamed, using MPMoviePlayerC...

When does it make more sense to use the factory pattern rather than an overloaded constructor to instantiate an object?

In Karl Seguin's Foundations of Programming there is a small section on using the factory pattern. He closes the passage by stating "you can accomplish the same functionality with constructor overloading", but doesn't indicate when or why? So,when does it make more sense to use the factory pattern rather than an overloaded constructor ...

Data structure for storing recurring events?

I'm looking for a data structure pattern for storing recurring events, but everything I came up with would result in a high number of special case handling or user input and data retrieval are overly complex. (I get the distinct feeling, that I haven't understand the problem domain well enough to do this.) How can I store Outlook-style ...

What performance overhead do IoC containers involve?

Hi, Loose coupling is wonderful of course, but I have often wondered what overhead wiring up dynamically using an IoC container (for example Castle Windsor) has over a tightly coupled system? I know that a detailed answer would depend on what the IoC was being used for, but I'm really just trying to get a feel for the magnitude of effo...

Patterns, Best Practices and Clean Code

I often find myself reading books and articles that outline patterns, best practices, and how to write "clean code." However, some of these concepts just seem to be over engineered and at times obscure the essence of the underlying problem, making the code more difficult to relate to the problem domain being modeled. How often do you fi...

When to Use the Decorator Pattern?

I am going over my design patterns, and one pattern I have yet to seriously use in my coding is the Decorator Pattern. I understand the pattern, but what I would love to know are some good concrete examples of times in the real world that the decorator pattern is the best/optimal/elegant solution. Specific situations where the need fo...

Only one record true, all others false, in rails

Hi, I have the following situation class RecordA has_many :recordbs end class RecordB belongs_to :recorda end RecordA has many recordbs but only one of them may be an active recordb. I need something like myRecordA.active_recordb If I add a new column like is_active to RecordB, then I have the potential problem of setting two r...

Where is a good place for data calculation methods? What should it be called?

I'm thinking of writing a class to store away some helpful methods that relate to my Model, sequences of my Model and my Repository. I don't think any of those are responsible for calculating anything. It's not really a service per se either. I want to do something like this: IEnumerable<Game> someGames; ... int score = _something.Calc...

Updating An API and A Custom RDB

So, I currently am working on a project, in which two different datasources will be updated. The business objects have similar structures, but not exactly the same. What I have currently planned on doing, is using a provider interface, so I have have a handler class to push to both databases. As the 2nd object is from an external AP...

What are UI Patterns?

What is the difference between User Interaction Design Patterns and User Interface Design Patterns. I have heard that one is the subset of the other, but how do thy correlate? What is the correct term for ui patterns e.g., from http://uipatternfactory.com/? ...

What separates a Ruby DSL from an ordinary API

What are some defining characteristics of a Ruby DSL that separate it from just a regular API? ...

What's the difference between the Dependency Injection and Service Locator patterns?

Both patterns seem like an implementation of the principle of inversion of control. That is, that an object should not know how to construct its dependencies. Dependency Injection (DI) seems to use a constructor or setter to "inject" it's dependencies. Example of using Constructor Injection: //Foo Needs an IBar public class Foo { ...

Generic Obeserver Pattern for User Controls

Hi there, I want to implement a generic Observer Pattern for user controls. What is the best way to do this? There are 3 usercontrols: A, B & C. Each of these usercontrols is a representation of a set of data. Each control has a select for display mode (basic or detailed). The site visitore gets to choose which mode. On changing the ...

Gang-of-four pattern usage in aspect-oriented-programming?

I am doing research on a SOA topic and i am trying to understand what gang of four say about aspect orientation. I also need to implement one of these pattern in AOP paradigm. What would be best pattern to pick for this? ...

suggestion on batch processing db records

I am working on developing a webapp (visual jsf, ejb3, hibernate on glassfish/mysql) that works with an existing legacy system. I have an 'employee' table (with fields such as name (String), location (String), etc.) which is separate from an employee table on the legacy db2 side. I do all of the webapp processing with my employee table....

Is the Prototype Design Pattern Really Just Clone?

I am doing an in depth study on design patterns, and I came across prototype, which I didn't really study before. I have searched the web and several books, and there isn't a really good example of prototype that could find that isn't just clone. Is the design pattern of prototype basically a language feature of java and C# as clone? ...