design-patterns

Do you know a good book/website about structuring your codes (PHP/ Web programming)

i mainly use PHP and I have been coding using it for a while. My main problem with PHP is that I think as your program gets bigger, it gets harder to maintain your code (probably applies for other things). I want to reduce this complexity in maintaining/modifying my codes. I want to make things modular and have rules when to start a new ...

Is there a good way to avoid unused method parameter in some of the subclasses while applying strategy pattern?

I have the following scenario where I have different kinds of sales algorithms to calculate the sales price. FixedSaleStrategy does not need basePrice parameter while all the other strategy implementations need it. Is there a good way to avoid this redundant parameter? public abstract class SalesStrategy { public abstract double Get...

Important things to keep it mind before a Code Review in Java

Hello, I have just created a mid-sized web-application using Java, a custom MVC framework, javascript. My code will be reviewed before it's put in the productions servers (internal use). The primary objective of building this app was to solve a small problem for internal use and understand the custom made MVC framework used by my emplo...

Am I using IRepository correctly?

I'm looking to use the IRepository pattern (backed by NHibernate, if it matters) in a small project. The domain is a simple one, intentionally so to allow me to focus on understanding the IRepository pattern. The lone domain class is Movie, with properties for Year, Genre, and Title. My intent would be to "get" movies whose properties m...

Resources for the state design pattern implemented in PHP?

I am looking for resources and examples of the state design pattern for PHP. Could anybody share these with me? ...

Find info about class in java, software design?

I have a bunch of classes extending an abstract Base class. Each subclass takes an array as in the constructor, (different length depending on class). These classes could be written by other people. What is the best way to figure out the length of the array the class needs? I could: (A) Require that each derived class have a static meth...

C# GOF Pattern Examples

Are there any C# GOF design pattern examples? I Keep finding this site which does have examples, but the "C# Optimised" examples are only available when you purchase one of their products. ...

hibernate dao design question

Im looking to create a generic DAO to handle CRUD in my hibernate app. My entities have most associations as LAZY fetching. But I find in order to have hibernate be efficient as possible with the SELECTs I have to create multiple methods on my DAOs. Here's what I mean: Entity A has two associations. Sometimes I want to retrieve this...

Recommended pattern for domain entities containing data from multiple databases.

Hi all I maintain an application which has many domain entities that draw data from more than one database. The way this normally works is that the entities are loaded from Database A (in which most of their fields are stored). when a property corresponding to data in Database B is called, the entity fires off SQL to Database B to get a...

public property vs static readonly

I am trying to decide among three different implementations. I have an IPerson interface, all people types (ie. police officer, student, lawyer) implement this. Each person type needs to have a different AddressLocation (ie. home, office, mailing). This location never changes so it can be static/readonly. People are handled generically ...

How should I model my code to maximize code re-use in this specific situation?

Updated: See end of question for how I implemented the solution. Sorry for the poorly-worded question, but I wasn't sure how best to ask it. I'm not sure how to design a solution that can be re-used where most of the code is the exact same each time it is implemented, but part of the implementation will change every time, but follow si...

Problem using abstract factory..

Hi, I am using an abstract factory to create user interface components such as dialogs. The abstract factory used is returned from a currently selected generic "INode" which is the base class for several different types of node. So for instance, if I want to add a new node of the same type as the selected node, the scenario goes someth...

What is the elegant solution for unrelated views in MVC web frameworks?

I've had a problem with the following issue in Rails and ASP.Net MVC. Often there are multiple widgets of functionality on a page, yet one controller action is supposed to render the page. Let me illustrate: Let's say I have a normal e-commerce site, and the menu is made of categories, while the page is to display an group of products...

Is the state design pattern overkill for a PHP form?

I have a page that, when accessed displays a table of information related to a video: Embed code Title Description Current gallery Thumbnail image This information is read-only when the page is first accessed. There is a select menu that has the following options: Edit Description Create Thumbnail (Upload/Replace) Edit embed code ...

Will the Factory Pattern solve my problem?

I have a requirement to create some objects that implement a given interface, where the type of concrete implementation being created is based on an Enum value. I run into trouble when the different concrete implementations require different parameters at runtime. This example (C#) is fine: public enum ProductCategory { Modem, ...

Change object behaviour...but just some lines!?

Hello there freaks & geeks. Here comes my question again, thanks for helping!. Lets suppose i have an object Foo, which method foo() does about 100 lines. foo() { ... qwert yuiop asdfg zxcvb nmhjk ... } If a developer wants to add some code to foo(), it can be easily done with inheritance, composing or a Decorator Pattern. But...

Is it possible to assign an interface to an object at runtime?

After reflecting upon all the great answers I received to my previous question about modeling my code to maximize code re-use, I started wondering if it would be possible to assign the interface to an object at runtime instead of when it is coded. Take, for example, a simplified portion of code from my previous question: public class O...

Question about abstract factories and injection.

Hi, This is similar to one of my other questions, but different enough I think to warrant a new question. Basically I am writing a user interface, and my user interface has nodes that can be selected. When a node is selected, the user interface ends up with an abstract node base class "INode". From this I get a factory by doing node->...

Visualisation of derived classes in C#

I have a base class (representing a real world container filled with small spheres) and some derived classes. This works just fine. My problem is how to do their visualisation. I have a UserControl visualising the base class. Is the best solution to have a derived UserControl for each of the derived classes? Or is it better to have just ...

How to refactor this code

I am currently refactoring some old code. I am looking for directions on the best design pattern to use here. I am thinking of the factory pattern but I am not sure if that's the best way to go or not. So here is a brief outline of the pseudocode. Class Foo has the core business logic in it. Class Foo{ private List<Things> stuff;...