design-patterns

How to refactor tightly coupled classes?

I'm trying to refactor a big tightly coupled application and trying to make it more maintainable and flexible. I've got many unit tests, so I'm hoping to refactor step by step. Which Design & Refactoring Patterns should I consider implementing / applying to accomplish this task ? I can think of some : Extract Interface Extract Meth...

What is this pattern called (helps avoid type casting)?

Found myself trying to find a link to an official definition of this design pattern which I believe I saw in Go4 but can't seem to find it anywhere. class Processor{ ProcessParameter(AbstractParameter x){ x.Process(this); } ProcessParameter(ParameterA x){ ... A-specific logic... } ProcessParameter(Paramet...

Does the Strategy Pattern violate the Single Responsibility Principle?

If the Single Responsibility Principle states that every object must have a single reason to change and a single strategy class implemented with the Strategy pattern (by definition) has multiple methods that can change for any number of reasons, does that mean that it's impossible to implement the Strategy pattern without violating the S...

Do you allow the Web Tier to access the DAL directly?

I'm interested in perceived "best practice", tempered with a little dose of reality here. In a web application, do you allow your web tier to directly access the DAL, or should it go through a BLL first? I'm talking specifically of scenarios where there's no "business logic" really involved -- such as a simple query : "Fetch all custom...

Access User context from a class library

Background: I have a win app and a web app and a shared class library. In my class lib I have some static methods for SQL queries which pick up my SQL connection string I store my SQL connection string in a Session variable since it is set at log in time where it is determined which database to use. My class lib cannot access my sessio...

What is the best way to design an application with entities that can be extended with additional attributes?

Looking for advice, links, design patterns, etc. on the best way to design an application where entities and related screens could be extended with additional attributes/related lookups via metadata/without recompile, ideally by end users. I'm thinking something very similiar to how Dynamics CRM 4.0 works with extension tables/dynamic p...

DDD: How should adding and removing related entities be modelled?

Say we have two aggregate roots in a domain model: Group and User. Now, Users can be added to or removed from groups. Using the repository pattern, I only modelled the following two interfaces so far: interface IGroupRepository { Group FindById(int groupId); } interface IUserRepository { User FindById(int userId); IQueryabl...

How to create a Singleton in C ?

Hello, I want to create a singleton in C. What's the best way? A concurrent solution would be nice.. Edit - I am aware that C isn't the first langague you would use for a Singleton, If it was the question was much simpler. ...

Null key in Identity Map

I have a domain object used in an identity map (the keys are the object's Id property). Pseudocode: map = new Mapping(); map[domainObj.Id] = 'foo'; I observe the object to tell me when it has been saved to the database: domainObj.bind('saved', function() { map[domainObj.Id] = 'new foo!' }) For new objects the Id field is empty...

How To Implement Shared Behavior Between Classes (Without Multiple Inheritance Of Course) in C#

UPDATE: So pretty much everyone here told me that i just need to start over again on how i designed my classes (thank you folks for your excellent answers by the way!). Taking the hint, i started doing extensive reading on the strategy pattern. I want to create behavior classes (or strategy classes) that inherit from an abstract base c...

What is the difference between the Data Mapper, Table Data Gateway (Gateway), Data Access Object (DAO) and Repository patterns?

I'm trying to brush up on my design pattern skills, and I'm curious what are the differences between these patterns? All of them seem like they are the same thing - encapsulate the database logic for a specific entity so the calling code has no knowledge of the underlying persistence layer. From my brief research all of them typically ...

Does the design pattern of temporarily hiding an object in another opaque object have a standard name?

I have a special kind of collection (in an object-oriented programming language) that provides a large range of persistence services, but that is also queried by other components. At times I have objects that I need to store in the repository, but whose type I would like masked from other services until it is ready (e.g., approved, or co...

Looking for specific design pattern

I'm looking for a pattern describing a certain situation. Maybe someone knows something and can give me a hint Situation Object of type A, 1 : n association to objects of type B. Example: A Person and all his pets. The pet objects have an age data member. Now each person should have a data member for the average age of his pets. I don't...

What's the best way to store PHP class attributes ?

Duplicate of: http://stackoverflow.com/questions/546403/whats-the-best-way-to-store-class-variables-in-php For some time I've been having this discussion with a co-worker on how should you store attributes within a PHP class. So which one do you think it should be used. Something like this: Class test{ public $attr1; publ...

Implementing Event-Generator Idiom in Java

I'm trying to implement the Event Generator Idiom (http://www.javaworld.com/javaworld/jw-09-1998/jw-09-techniques.html). I find things to be a bit "odd" when it comes to the observable class though. Let's say I have the following classes: interface BakeryListener + orderReceived(BakeryEvent event) + orderProcessing(BakeryEvent even...

Is this Factory Method creation pattern?

I have been using factory method creation pattern for awhile now. I was just recently told that this: public static class ScheduleTypeFactory { public static IScheduleItem GetScheduleItem(ScheduleTypeEnum scheduleType) { IScheduleItem scheduleItem = null; switch (scheduleType) { case Schedule...

alternative to MVC that is loosely coupled?

I work in a web shop as a PHP programmer. Most of the time we use good coding practices but not much structure to the site as a whole. I have now entered my phase of being bored with some of our practices and want to branch out and simplify and generate some things in a helpful way not just for me, but the hybrid-programmer web develop...

How is the Observer pattern different from an Event driven model?

I am a senior level developer but I haven't had a lot of formal training and I although I have used many design patterns and seen them used in my years as a developer, no one really went out of their way to say. "Oh this is an observer pattern, or this is a Singleton pattern." Reading over some of the design patterns, I came across the ...

Is the MVC (Model View Controller) paradigm a better way to develop or just a new complex one?

I was trying to use RoR or ASP.NET MVC but at my first impression it seems to me that MVC is a drastic way to change the programming paradigm. Is this just my resistance to changes or it is really weird? Some times i feel really lost! Any suggestion or I just have to turn back and program in the old fashion way? ...

After creating a new row in the database, should I return the primary key to the row or a data transfer object?

I have a three tier system, SQL Server backend, hand written data access layer, and using stored procedures. I have a table called EventTable. Each row is an 'Event'. An Event has a primary key, and a start date. CREATE TABLE EventTable ( ID INT IDENTITY(100,1) PRIMARY KEY, StartTime DateTime NOT NULL ) There is a stored proced...