design-patterns

Design Patterns and Encapsulation for Procedural Programming?

I'm working on a fairly large PHP project written in a procedural style (it was written before PHP 5), and I can't help but feel that some of the things I'm doing are a little "hackish." A modification somewhere else can easily break the application. All the design patterns and best practices I've seen seem to only apply to OOP. I cou...

Recommend class design in Objective-C

I'm new to Objective-c. For learning purposes I'm trying to build something like a phonebook. So I'll have a class called Person that will have some properties (name, phone, etc). Right now I'm not preoccupied about persistence. But, I need something to "hold" Person objects. So I thought about create a class called People, but I don't ...

Why is checking if two passwords match in Django so complicated?

Am I doing something wrong, or is this seriously what the developers expect me to write every time I want to check if two fields are the same? def clean(self): data = self.cleaned_data if "password1" in data and "password2" in data: if data["password1"] != data["password2"]: self._errors["password2"] = self.e...

Is factory method appropriate here?

I am generating a sequence of Step objects that differ by "Type" and data contained within. e.g: The Step objects should basically be structs that look like this { GRAB, CASCADE_ONE, FACEUP, SOMEOTHERDATA }, { DROP, DECK, FACEDOWN, MOREDATA, ANDSOMEMORE }, { MOVE, 34, 89 }, where GRAB, MOVE and DROP indicate StepType: typedef enum ...

What design is better: universal builder or several concrete methods?

I need to create an email-notification service (as a part of a bigger project). It will be used to send several types of notification messages which are based on html-templates. I can design it in two ways: The first way is based on the builder pattern. It's universal (as I think) and can handle all necessary cases. But it's not ve...

How should I approach to fix a DNN web application?

Myself and my team is taking over a DNN web application done by a software development vendor. There are some issues like 1. redundant non-standard data / API to access to tab and configuration of a module, and 2. some other architecture related issues. My goal is to remove things we don't need and steer the application back to DNN be...

LINQ to entities - best practices for passing models

As we all know most apps have a data access layer, often using repository classes. Typically we want the repository to operate with strongly typed objects, e.g. interface IUserRespository { User GetUserByID(int id); void AddUser(User u); ... and so on } However, sometimes we want to make a more complex query on a DB, ...

Questions with different types of answer in NHibernate

I'm trying to find a tidy solution to a questionnaire problem. Let us say that I have a Questionnaire class which has a collection of Answers, e.g. public class Questionnaire { public virtual ISet<Answer> Answers {get;set;} } Answers need to be of different types depending on the question, e.g. date of birth, marks out of ten, why...

Best design pattern to use: adapter or facade

I have a question relating to the best use of a design pattern. Its probably my understanding of the patterns thats confusing things but i cant decide which pattern is best suited to the following problem. I have a client system who will be interacting with a seperate subsystem. The subsystem is quite complicated and so i need an inte...

Composite pattern with different types of objects

I'd like to use the Composite pattern for forwarding calls received by one object to others. At present, objects on the receiving end are all of the same Abstract type but the snag is that they selectively accept different types of objet as parameters according to their concrete type (think different models). As far as I can see, ther...

Repository Pattern: How many repositories are needed to get a Contact with two Addresses?

If you have one Contact, with a 1:* relationship with Addresses, and possibly one or more other tables used to hold the persisted value objects -- how many repositories should there be? Should there be just one ContactRepository with one public method (GetContact(), that internally calls a private method (GetAddresses)) that returns a...

Entity Framework: How to use entities as in-memory business objects

Hi, I'm sure most people who use the entity framework sometimes need an entity only for some business operations without it actually ever getting persisted to the database. For example, an online shop checkout wizard where you want to fill the customer and address info, but only persist it once the customer is at the end of the wizard a...

Help me to avoid multiple inheritance aka. help me to get proper oo design.

I have two classes LightA and LightB. I have the source code of LightB but not that of LightA. I extended LightB with LightDimDip. ie LightDimDip:extends LightB. Now I need to apply DimDip feature to lightB also. Can any one suggest good OOP design. Once again I remind you people that I cannot modify LightA. ...

Implementing MVC/MVP Design for TabControl ..design question

Hi All, I have a an Winform application with 2 forms. In one form I have a Tab Control with 3 Tabs and navigation buttons to switch between tabs. On the first tab the user selects a file and on navigating to next tab i want to do some processing on the file selected in the first tab,and show the result in the 3rd tab. The other form j...

Implement a PHP singleton: static class properties or static method variables?

So, I've always implemented a singleton like so: class Singleton { private static $_instance = null; public static function getInstance() { if (self::$_instance === null) self::$_instance = new Singleton(); return self::$_instance; } private function __construct() { } } However, it recently struck me th...

Fast undo facility for bitmap editor application

I'm trying to make a bitmap editor app for the iphone which would be similar to Brushes or Layers or a cut-down version of Photoshop. I'd like to be able to support 1000x1000 resolution images with about 4 layers if possible. I'm trying to design my undo/redo system before I write too much code and I'm having real issues coming up with ...

Design problem relating to manipulating unkown types

Hi, I am stuck with a design problem that I hope you guys can help with. I have a few different classes that have various parameters (more than 20 in each case, and they are mostly different, although some are exactly the same in which case they inherit from a base class). I want to control these parameters through the user of a class c...

Service Interface Design - Exception or Object Hierarchy?

I'm currently writing an app that posts some data to a HTML form and parses the resulting HTML response page. Depending on the input my user sends the HTML response can either contain valid payload data or request that the user validate an error in the data they entered. I'm slightly confused as to how to implement the interface for ...

best design pattern for data validation / multiple conditions

Hi what would be the best design pattern to use for a data validation scenario where lots of values get passed to a function and all must be checked to be in the correct format and length etc. At the moment im using multiple if statements but it seems very messy. ...

Which design pattern allows abstraction of functionality based on runtime types?

I have an abstract class A and several implementations of it. I expect this to evolve over time, by adding more implementations. I also have an interface that does something at instances of the above class hierarchy (eg print them). I want implementations of the interface to provide some special functionality for some of the subclasse...