design-patterns

Java Reflection bad pattern?

Let's say I have a lot of similar classes (Units in a RTS in this example), that is, the class Unit, and the subclasses UnitA,UnitB,UnitC etc. All Unit classes have the following constructor (including Unit) public class UnitX { public UnitX(FileReader fr) { ...read parameters for constructing the unit... } } My file...

Is this a common design pattern? "Descriptor pattern"?

Is what I'm doing below a common design pattern? If so, what's the name? I have a complex object that has "simple" fields like Strings and lists of Strings, as well as other complex objects. I want to add instances of this object to a JMS message queue, which means they need to be Serializable. I don't want to make the entire object gra...

How to Refactor a fat interface?

Lets say i have the following set of interfaces.... public interface IStart { void M1(); bool IsWorking { get; } } public interface IStartStop : IStart { void M2(); event EventHandler DoM1; event EventHandler DoM2; } public inter...

Head First Design Patterns: Decorator behavior puzzling

This is a question on the behavior of the code rather then the pattern itself. I will lay out the code below public abstract class Beverage { protected String description; public String getDescription(){ return description; } public abstract BigDecimal cost(); } public abstract class CondimentDecorator exten...

patterns to use when building complex web UI

I need to implement a wizardy, dynamic UI that uses complex validation of the style: If A = 1, show controls B, C, D. B is required, C is not, and D is not required must be less than 30 if it is populated. If A = 2, show controls B, D, E. B is not required, D is required but has no limits, and E is not required. If B is not null, show ...

Suppose I want to customize the look and feel of my website for my corporate clients...

Given: I have a website that includes both ASP.NET Web Forms and Classic ASP web pages. Multiple companies are willing to pay to customize the look and feel of this website. Question: Are there any well known design-patterns, books, or online resources that detail customization best-practices? EDIT: Are ashx handlers a good way...

Is it a good idea to extract controller logic into a service that extends repository functionality

Hi, I had a controller POST action that is called List that accepts a status variable which can be the following values { "all", "active", "inactive}. Then I made repository calls based on the the value of "status" inside of the controller. The controller looked like this: [HttpPost] public ActionResult List(string status) ...

Create User and Edit User - DRY or separation, which is more important

I'm wondering what more experienced developers think about how to handle almost identical processes, such as a user creating a profile and a user editing their profile. At the moment I have a single controller method and single view which handle the distinction between a new user and existing/editing user, just by passing around an $edit...

Decorator vs Strategy Pattern (vs ?) to extend functionality

Hi, I've been trying to read through different implementations of Scene Graphs for 3D engine development to learn design patterns used in this domain, but unfortunately the code bases are too big for me grasp (yet, hopefully). So, let's say we have a class Model that stores pointers to geometry, shaders, textures etc. and we want to a...

Design(How-to) of classes containing collections of other classes

Hi Everyone, How to design classes involving collections of other classes? General Example: A Workspace contains number of Projects . A Project contains large number of Resources . Each Resource may contain large number of Files. So here the classes identified can be Workspace,Project,Resource and File. Workspace will have list ...

Implementing the decorator pattern in Python

I want to implement the decorator pattern in Python, and I wondered if there is a way to write a decorator that just implements the function it wants to modify, without writing boiler-plate for all the functions that are just forwarded to the decorated object. Like so: class foo(object): def f1(self): print "original f1" ...

How to implement one producer , multiple consumers and multiple Objects in Java?

I have a question about Producer/consumer Design pattern , in fact my situation is :I have One class that produce multiple types of messages (notifications) and multiple consumers who consume those messages. The complication is my Producer produce different types of messages and my consumers consume those messages . So what is the best...

What to do with proxy class copy-assignment operator?

Consider the following proxy class: class VertexProxy { public: VertexProxy(double* x, double* y, double* z) : x_(x), y_(y), z_(z) {} VertexProxy(const VertexProxy& rhs) : x_(rhs.x_), y_(rhs.y_), z_(rhs.z_) {} // Coordinate getters double x() const {return *x_;} double y() const {return *y_;} double z()...

Reusable JS ajax pattern (jquery)

I'd like to know if there is a better approach to creating re-usable ajax object for jquery. This is my un-tested code. var sender = { function ajax(url, type, dataType, callback) { $.ajax({ url: url, type: type, dataType: dataType, beforeSend: function() { o...

Recommended open-source software to study C# and design patters (MVC and others).

HI After reading some posts here on StackOverflow.com I decided to start studying code from other developers to improve my coding skills. I'm looking for a open-source software that uses MVC pattern, and also most design patterns possible. Could you recommend some open-source software written in C# or VB.NET that uses as many design p...

Pattern/Strategy for creating BOs from DTOs

Hi, I like the approach of having property bag objects (DTOs) which define the interface to my server, but I don't like writing code like this: void ModifyDataSomeWay(WibbleDTO wibbleDTO) { WibbleBOWithMethods wibbleBO = new WibbleBOWithMethods(); wibbleBO.Val1 = wibbleDTO.Val1; wibbleBO.Val2 = wibbleDTO.Val2; } This copy...

Is CoreData typically used as the Model or is it an implementation detail of the Infrastructure?

I would like to use a Sqlite datbase in an iphone application. The example in the book I am reading has the controllers directly calling into CoreData objects. Coming from MVC/MVP in .NET to me this is akin to opening a SQL Connection in a button event handler. I would typically have a repository that handled the details of retrieving...

Designing a Multi-Tier Application (Template style)

Hi! Im planning to design a project (n-tier) that is easy to customize and maintain without compromising efficiency... here is the draft of my (unique :)) design layout base on what I learned on how to built ntierarchitecture... The project is composed of 3 DLLs (+1 for Helper Classes) and the UI BusinessRules.dll (Compose of 2 subfol...

Observer design pattern and others

I'm starting to read about design patterns and trying to apply them to some coding. I've read about the observer pattern and think it would be a most useful one to make use of. My two questions are these: 1) If I want my object to be both an observer and a subject, is it simply a question of making it inherit from both the observer and...

How to handle service and eventbus instances in GWT MVP Architecture?

We are developing an app using the MVP pattern, as described in this guide: http://code.google.com/webtoolkit/articles/mvp-architecture.html When creating the controller instance we do the following: appController = new AppController(service, eventBus); appController.go(RootPanel.get("SOME_SLOT")); Now, when the controller creates a...