design-patterns

How to approach design problems like "design a vending machine"

Hello, I wanted to know what are the steps that I should follow to approach problems like design a vending machine and come up with a number of design documents (like use case, sequence diagram, class diagram). Is there any source/link that I can read where it talks about how to go step by step. Thanks. ...

OO design patterns to use for validation

I am in the process of writing some validation code based on these assumptions: Validation code must be in an external class i.e. no data class contains it's own validation The same object can be validated in different ways e.g. validate syntax only; validate against DB look-ups; validate against duplicates; etc Validation output c...

nullobject for File in Java

I have a class that occasionally gets passed null for File objects. During normal operation it uses a Scanner class to parse through the file. Instead of littering my code with null checks against the File objects, I thought I could replace the Files with nullobjects (Gang of Four style). However, it looks like File isn't really design...

Splitting ASP.NET MVC Controllers

How should one split up the controllers in an ASP.NET MVC site? For example, the default project has a HomeController and an AccountController. Should there be one controller for each section of the site, or something else? I'm learning how to use the MVC framework, and any help would be appreciated. ...

Ideas for Implementing multiple views for the same data

My question is based in structure and architecture really and I'm after ideas on the best way to implement the following: I am using code igniter (although you could presume any MVC framework). I have a custom CMS which allows for the management of 5 different websites. Users log in and switch between these sites. They can add content t...

Can you suggest book on program stucture?

Hi, I was programming for a while. Starting at school, writing small utility programs as a hobby and now professionally. My problem is I'm getting distracted while writing software (I come up with a new feature and fallow it immediately) so my code is usually disorganized. Now when I’m starting my career as a professional developer I fi...

Is this a textbook design pattern, or did I invent something new?

I'm fresh out of designing a set of tables, in which I came up with an architecture that I was very pleased with! I've never seen it anywhere else before, so I'd love to know if I've just reinvented the wheel (most probable), or if this is a genuine innovation. Here's the problem statement: I have Employees who can each sign a differen...

Architectural MVC and Swing

I want to use MVC to structure my Swing application, but there seems to be a conflict. As I understand MVC, the controller should handle input and update the model. The model should notify its observers of which the view is one. I have two problems Swing is all part of the view. The fact that components have their own models is an im...

What are the patterns in html/javascript RIA development?

When building big GUI based applications in other languages like C# or Java, we have various patterns like MVP, MVC, MVVM, and even complete guidance packages like Prism (WPF/Silerlight) that help us keep our code maintainable, extendable and keep the complexity of the application at a sane level. But when it comes to big RIA applicati...

How would you create xml files in java

I am creating software that creates documents, (Bayesian network graphs to be exact), and these documents need to be saved in an XML format. I know how to create XML files, but I have yet to decide how to organise the code. At the moment, I plan on having each object (i.e. a Vertex or an Edge) have a function called getXML() (they will...

What design pattern and strategy for a Request base system for actions [C#, PHP]

Hi all, I am doing a RogueLike game, and would like to make the logic for each entity modular. This probably could apply to web applications where there are roles and permission control too. The idea is to have something like this - we have different type of entities in the game. a door can be bashed down, while a stone wall cannot be ...

How to handle type redundancy in external libraries?

I'm writing a computer graphics application that makes use of several different libraries that provide many of the required features. For example, in college I wrote quaternion, optimized 3 vector, and optimized 4x4 matrix classes that I like to use since they are efficient and I'm very familiar with them. I also wrote a K-D Tree imple...

Design problem: fetching more data for some of the records I retrieve in an sql query.

Say I have a query that fetches [type][show_name]. For all [type]==5 records, I need to join them with another table. What would be the best approach for that: Join for all records between the two tables (looks bad). Run the query and then run again on the result set, fetch all the IDs and do a IN query on the table I need to join...

Windows Form MVC

Hi, I am building a Windows form application using .NET 3.5. I would like to use the MVC design pattern. The app has two forms: a quick launch and a view showing the details. The quick launch just has a tree with 2 levels, so the tree structure looks something like Category 1 Subcategory 1-1 Subcategory 1-2 Category 2 Subcategory 2-...

Using generics when type is not known at compile time

Platform: C# 2.0 WinForms I have a factory class that provides an instantiation of a particular data mapper depending on the type that I send it, the code is as such: public static IDataMapper<T> GetMapper<T>() where T: IDto { Type mapperType = MapperLocator.GetMapper(typeof(T)); return (IDataMapper<T>)mapperType.Assembly.Crea...

When to separate columns into new table

I have company, customer, supplier etc tables which all have address information related columns. I am trying to figure out if I should create a new table 'addresses' and separate all address columns to that. Having address columns on all tables is easy to use and query but I am not sure if it is the right way of doing it from a good d...

Design Pattern for building an object from a more complex object

I'm in the middle of refactoring some code on my current project, and I'd like some input on if any design pattern exists for the following scenario. I have a class which executes some logic and returns an object containing the results of said logic; Let's call this the Result object. The state information contained in the Result objec...

Default Value Storage

I have the following three tables: Item Code ItemCode (many to many relationship between Item and Code) And then I have the following sample data on the third table: Item | Code -----+----- 001 | A 002 | A 003 | B There's a possibility that a new Item is added but does not have a code yet. I will assign a default code for this ...

Is MVC/MVP with Winforms an anti-pattern?

I have seen some developers attempting to shoehorn the MVC or MVP patterns into Winforms applications, presumably on the premise that, if it's good for WPF and ASP.NET, then it must be good for Winforms. Is this a good idea, or is it lipstick on a pig? Why or why not? ...

OO game design question

Hi SO, I am programming a simple game in Java but I am trying to do it 'right' with a nice clean design and no hacks. I have two classes GamePanel that receives clicks and keypresses and Model which contains all the Entities and is responsible for their updates. The Model needs to know where the user's mouse is but I can't decide on...