design-patterns

Is it feasible to create a NullObject for every class? ( with a tool of course )

The NullObjectPattern is intended to be a "safe" ( neutral ) behavior. The idea is create an object that don't do anything ( but doesn't throw NullPointerException either ) For instance the class defined as: class Employee { private String name; private int age; public String getName(){ return name; } public int get...

MVC: What's better, one large repository per db or one per business entity?

This time I have a more philosopical question. Most MVC tutorials/books seem to suggest to restrict the scope of one repository to one aspect of the model and set up multiple repositories to cover all model classes. (E.g.: ProjectRep, UserRep, ImageRep, all mapping onto the same db eventually.) I can see how that would make unittesti...

= Try Except Pattern?

I find this design pattern comes up a lot: try: year = int(request.GET['year']) except: year = 0 The try block can either fail because the key doesn't exist, or because it's not an int, but I don't really care. I just need a sane value in the end. Shouldn't there be a nicer way to do this? Or at least a way to do it on one line? Some...

Why should an abstract class implement an abstract method of an abstract base class ?

In the following example, the class Derived implements the abstract method method from class Main. But I can't think of a reason to fill in the method body in the abstract Derived class' implementation. Surely I should only implement abstract methods within real classes. So how can I avoid doing it? What else can I do? abstract class ...

What's the best design pattern for PHP when Class_a only occasionally needs Class_b information?

This project is in PHP, but is fairly language agnostic. I'm building a project that has the following MVC format Main_Class Main_Class_Common --> Class_A --> Class_B --> Class_C --> Class_... --> Class_K Original requests go to the Main_Class which then includes the appropriate main sub class. The majority of a request will...

When to use template method pattern

Hi I have a problem where i have to perform similar steps / actions (which differ slightly) on different sets of data (the data can be slightly different also with regards to its strucure). There are a few steps that i need to perform: connect, validate, build error messages if required, change the strcture of the data in to a set forma...

Converting data representations and managing errors

Hello, say you are implementing an api that usually takes data in the form of associative arrays, processes them for validation etc and converts them into a different format (still an array, although the keys and overall structure is different), and then sends them off to get processed further. What would be the best way to handle this....

Singleton PHP - database handler

Hi, I have been reading a bit lately about the singleton pattern. When readin the technical aspects of it, it appears to be ideally suited to managing a database handler or the likes. But after reading wider resources it appears that the developer community really does not favour the pattern. I am struggling to find a better solution ...

Binary communications protocol parser design for serial data

Hi, I'm revisiting a communications protocol parser design for a stream of bytes (serial data, received 1 byte at a time). The packet structure (can't be changed) is: || Start Delimiter (1 byte) | Message ID (1 byte) | Length (1 byte) | Payload (n bytes) | Checksum (1 byte) || In the past I have implemented such systems in a procedu...

UI pattern to allow user to add item with unlimited sub-items

Hi all I'm writing an ASP.NET app. I need to include a page where the user can add an item which has several sets of subitems, each of which sets is unlimited in number. The subitems themselves contain between 10 and 15 fields, so need a fair bit of UI space. As an example of what I mean, the user needs to be able to add a Business rec...

modelLocator design pattern

Hi, Any one please explain the modelLocator design pattern with simple example and where and when we are going to use this.? Thanks, Ravi ...

Is there a useful design pattern for chained asynchronous/event calls?

I'm currently having to integrate a lot of web service calls inside Silverlight that make calls similar to the code below. No user interaction should be possible until the loading of all 3 is complete. // In my view, having standard delegate methods (non-anonymous) makes the // code below even messier. // I've left out the EventArgs t...

Why classes tend to be defined as interface nowadays?

Hi, These 2-3 last years, many projects I see, like Cuyahoga open source C# CMS, tends to define persistent and non persistent classes as Interface. Why? Is there a good reason? TDD? Mocking? A design pattern? ... ...

Single Responsibility and Mixins

Given that Mixins generally introduce new behaviour into a class, this generally implies that a class would have more than one behaviour. If a class has a single responsibility this is defined as the class having only one reason for change. So, I can see this from two different perspectives The class only has one reason for change....

Creating an "over time" algorithm

What I have is a LineItem object and a collection called LineItems that holds LineItem objects. My LineItem objects have a property called ItemDate (DateTime data type) and another property called ItemAmount (decimal data type) and another property called ItemCategory (integer data type). What I am trying to do is write a function in my...

NHibernate : pattern for returning fully loaded instances from repositories

Hi all As part of my endless NHibernate-inspired DAL refactoring purgatory, I have started to use the Repository pattern to keep NHibernate at arms length from my UI layer. Here's an example of a Load method from a repository. public StoredWill Load(int id) { StoredWill storedWill; using (ISession session = NHibernateSessionFactory...

Singleton, Registry or config files for db handler

Ok im going to keep this really simple. Which method is the best for the likes of db handlers in an application: Singleton, Registry pattern, static configs class or config files. Ive been reading about this and there seems to be a lot of contradictory ideas on this. I understand that there wont be a one fits all solution but gener...

What design pattern works for you? ASP.NET with MySQL.

Hi this is a question to all experienced developers who create their web applications using ASP.NET(C#) with MySQL. I am currently using the Microsoft Enterprise Library to implement a database factory design pattern. I have a DAL which returns a DataTable. I have a BLL that executes that DAL which returns a List<> of my DataObjects. T...

Pattern for website content that updates periodically?

I often find myself designing simple little web projects that are serving up aggregate content or doing a 'mashup'. Typically this involves running a script to scrape/parse/manipulate some data periodically, then serving that as 'static' content. I run the 'refresh' script as a cron job that generates HTML that is served up to the end-...

Famous design patterns that a C++ programmer should know

Possible Duplicates: list of c++ tricks with names What C++ idioms should C++ programmers use? After reading books like C++ Primer, Effective C++ and TC++PL I want to learn some important design patterns. So, what are the famous design patterns that every C++ programmer should know? ...