A design pattern is a general reusable solution to a commonly occurring problem in software design.

learn more… | top users | synonyms (1)

1
vote
2answers
42 views

Do you still need created_by and updated_by attributes with dedicated auditing?

For as long as I have been writing database-backed websites, I have included created_by, created_at, updated_by, and updated_at in every single table. As you can guess, whenever a record gets created ...
2
votes
2answers
48 views

Delegating work and programming to component interfaces

I have a MessageHandler class which receives and validates messages before determining which components in the architecture they should be delegated to so they can be processed. This involves calling ...
5
votes
2answers
478 views

Is using interfaces for datatypes an anti-pattern?

Suppose I have a various entities in my model (using EF), say User, Product, Invoice and Order. I am writing a user control that can can print the summaries of entity objects in my application where ...
1
vote
1answer
63 views

Nested REST urls and parent id, which is better design?

Okay, we have two resources: Album and Song. Here is API: GET,POST /albums GET,POST /albums/:albumId GET,POST /albums/:albumId/songs GET,POST /albums/:albumId/songs/:songId We know that we hate ...
4
votes
2answers
179 views

Why does 'zip' ignore the dangling tail of the collection?

C#, Scala, Haskell, Lisp and Python have the same zip behaviour: if one collection is longer, the tail is silently ignored. It could be an exception thrown as well, but I didn't heard of any language ...
0
votes
1answer
39 views

Is Current CoffeeScript Module Pattern Valid?

I have a Node.js web application that's written in CoffeeScript, which has a set of "services". These various services are currently exposed as a CoffeeScript class, which does a few things that I ...
0
votes
0answers
37 views

What architecture/design to adopt when consuming a RESTful API? (iOS App)

TL;DR 1) I want to refactor the biggest part of the app on which I work - and it is pretty much spaghetti. It's a single class that makes the requests to the server, parses the JSON and saves the ...
2
votes
1answer
92 views

How to name a function that makes sure an element exists and returns it?

function getOrInsertEmptyElemById(id){ var elem = $(id) || document.body.insert('<div id="'+id+'"></div>'); return elem; } I find myself using functions like the above quite ...
0
votes
1answer
50 views

Methods accounting for all input to method

This is more of a conceptual question. Let's say that you had the following enum public enum FooEnum { ALPHA, BETA, GAMMA, DELTA; } And let's say you have the following method: ...
-4
votes
0answers
45 views

Differences between books in the principles of computer programming, and in programming languages [on hold]

What are differences between books in the principles of computer programming, and in programming languages (whose purposes are not for specific languages)? I am often confused by them. I heard ...
2
votes
0answers
35 views

What design pattern is used in this delegating scenario?

I am currently having to bend some framework API to fit my usecase. The framework provides generic interfaces such as public interface Processor<T> { T process(T t); } with various ...
0
votes
1answer
23 views

Design of actions handlers requiring some order

I have a REST application where 'actions' can be executed to perform anything in the system. For example: user.save, user.get, etc... I also have pre and post execution 'handlers'. For example a ...
3
votes
0answers
92 views

What kind of programming pattern is appropriate for programming an algorithm with rules and exceptions?

I'm interested in coming up with an algorithm to solve a guessing game. The player is attempting to guess a sequence of 4 unique numbers from 1 to 9. After a guess, they are told how many numbers of ...
-1
votes
3answers
153 views

How to design a solution that needs dynamism using Inheritance [on hold]

I have below code/classes/interfaces: An Interface: public interface Animal<A extends Animal<A>>{ void fight(A otherAnimal); } 2.Tiger class which is implementing Animal ...
0
votes
4answers
231 views

2 methods that are 75% the same? [on hold]

I have code that violates the DRY principle and I would like to consolidate 2 methods as much as I can, but the problem I am facing is that they have some differences, I would say they are about 75% ...
-3
votes
1answer
44 views

Ask advice on the improvement of my code [closed]

My original part of the code for a matrix class is like this: Matrix::Matrix(const Matrix& mat) { int i; r = mat.r; c = mat.c; d = new double [r*c]; double* p = d; double* pm = ...
32
votes
11answers
3k views

Constructor-only subclasses: Is this an anti-pattern?

I was having a discussion with a co-worker, and we ended up having conflicting intuitions about the purpose of subclassing. My intuition is that if a primary function of a subclass is to express a ...
2
votes
1answer
186 views

Reducing the complexity of over-designed code

I have just started working at a company where I have inherited a C# codebase from a previous developer. I know programming well, have an engineering degree + an (unfinished, several year long) PhD ...
1
vote
2answers
110 views

Sharing code logic between controllers, through the Model layer?

As I originally conceived my Model layer, it was only supposed to hold data and no code. I receive DTOs from web-services, they are mapped into my Model objects. Those model objects usually end up ...
1
vote
1answer
121 views

Problems with OO design for application with pluggable components

I'm trying to refactor an ugly code and make it easly extendable in the future. The application should be nothing else but a series of components that have input(s) and output(s). The components ...
2
votes
2answers
124 views

Is there a name for a dictionary that returns the key as the value by default? [closed]

A dictionary that returns the key as the value by default can be used in cases where exceptions or translation is needed. E.g. One could do i18n = SpecialDict() if spanish: i18n["Hello"] = ...
2
votes
1answer
70 views

Scheme/Design Pattern for allowing a certain outside class to set properties

I came up with a solution (in PHP) to a problem and am wondering if it is a named Design Pattern, and if it is good practice. I have a collection class and an item class. The collection class is the ...
2
votes
1answer
189 views

What is SteppedPattern?

I read this article on Jon Skeet's blog where he delves into the topic of performance on object pooling & thread safety. In the article he makes a reference to SteppedPattern: Most of our ...
0
votes
1answer
43 views

What is the better way of getting different outputs for two very simmilar related workflows

I have a very concrete scenario but I think it would be quite frequent. I'm trying to come up with a solution that it's "better" by better meaning more scalable, reusable and not smelly. I'm working ...
1
vote
2answers
74 views

Design Pattern for Removing Default Listeners

We have a standard GUI control with a bunch of default listeners like that: class OurControl extends Control { OurControl() { addMouseWheelListener(new DefaultMouseWheelListener()); ...
1
vote
1answer
85 views

Consuming a rest API that exposes nested objects

I have a series of nested objects, exposed over a REST API, like so: class Categories { int id; string name; List<Subcategories> subcategories; } class Subcategories { ...
0
votes
1answer
125 views

Better pattern than large if/else if/else for checking conditionals [duplicate]

I've got a fairly large set of booleans I'm checking in javascript, and then using them to alter the state of a layout in my React app. The whole thing is unwieldy, difficult to read, inelegant, and ...
0
votes
1answer
48 views

Pattern for separating UI code from logic in Wicket

I'm using Apache Wicket for developing web apps, I have developed a few for the last year and it has been great; today I was looking at a few pages and most of them look like this: public class ...
1
vote
0answers
32 views

Strategies for maintaining backwards compatibility when persisting objects to XML [duplicate]

I am using XStream to persist Java objects to files. This works fine and so far I have had no problems. However, in the course of development, the objects have changed. Some new properties have been ...
0
votes
0answers
74 views

Choosing the right design pattern/architecture for a scenario

I have a situation, in which I would like your opinion about the best approach that I should take. Let's consider 10 classes (obj001, obj002 etc.) all which represent some business entities, and are ...
0
votes
1answer
116 views

Why use the Singleton pattern over class functions and fields? [duplicate]

I'm going to start by saying that I understand that programming in mostly class functions and variables can be harmful to object-orientation, and that most of the time an instance is preferred. I'll ...
1
vote
0answers
36 views

Injecting data processing logic into class

I want find more elegant and appreciate way to inject processors into CommandProcessorDispatcher class. Or it can be another one solution (the goal is separate each command processing logic to ...
16
votes
1answer
694 views

When to use prototypical programming in JavaScript

I've spent a good bit of time developing simple widgets for projects in the following way: var project = project || {}; (function() { project.elements = { prop1: val1, prop2: val2 } ...
1
vote
2answers
121 views

Which design (pattern) would be suitable to abstract logging platforms?

I need to create a simple system to abstract logging platforms. The idea is that I'd like to be able to exchange or activate a logging platform (nlog, log4net, enterprise library) via some ...
0
votes
0answers
46 views

Possible way to make java class builder more abstract by using interface required keys

I'm looking for a more abstract pattern for builders that handles required fields without the need of writing a validator that checks if all requried fields are set. I like this builder. But is ...
0
votes
1answer
66 views

Is this a good service locator, and is this service locator pattern(?) OK?

I'm working in Zend framework 1 and was using Zend_Registry to store objects so that I could replace them in my controllers while unit testing: $auth = Zend_Registry::get('Auth'); // set in ...
0
votes
0answers
41 views

Design pattern for multiple companies in AngularJS

We are on the verge of launching v3 of our in-house product. v2 was written completely in AngularJS and V3 will be the same, but written completely in Typescript. We have a few customers that have ...
1
vote
1answer
84 views

mySQL / PHP design pattern - one function multiple queries

So here's the gist of it. I'm looking for a design pattern where I can have one function, say queryHandler that gets the query and the parameters from a number of different functions and returns the ...
1
vote
1answer
171 views

Should I use Strategy Pattern for this task?

I'm setting up a data validator that will iterate through the rows of a spreadsheet, and for each column, perform a validation check. I was thinking that this might be an appropriate task for the ...
1
vote
1answer
51 views

Should factory make context or concrete strategies objects in strategy-factory pattern?

In a typical strategy pattern class Strategy { public: virtual int execute() const = 0; } class StrategyA : public Strategy { public: int execute() const override; } class StrategyB : ...
1
vote
1answer
99 views

Design pattern where decorated object may ask for things like “status updates” from the decorator to perform it's role?

Here's an situation that has haunted one of my open-source projects for quite some time. Imagine if you could represent every front-end input form with a single backend object? An object that ...
21
votes
3answers
1k views

Caching at business layer vs Caching at Data Layer

I have always worked on projects where caching was done on DAL, basically just when you are about to make the call to database, it checks if data is already there in the cache and if it is, it just ...
0
votes
2answers
101 views

Should methods perform checks that they accomplished the task they were built for? or should they just throw an exception?

What are some pro's and con's of validating your performed the task intended? public static bool UploadFile(string filename) { // 1. upload the file // 2. check to see if the file now exist ...
4
votes
1answer
199 views

Should I be using separate 'domain' layer?

I have been reading a lot about domain layer and DDD. However I am still confused about it. To me they seem to be a fancy name for business classes however more modelled towards your application ...
0
votes
1answer
103 views

Change routing to comply with Law of Demeter

I have a Task, Owner and Plan. Charge values are kept in a plan, owner is on a particular plan and task knows its owner. A task needs to setup its charges based on the knowledge the owner has. Owner ...
4
votes
3answers
246 views

One controller to rule them all?

I am developing a single-page application. The page has a toolbar. When the user clicks on any button, it visually creates a tab, and triggers an ajax request to the required controller. Now two ...
2
votes
1answer
87 views

How to add permissions checks 'after the fact'

I have a great number of PHP classes which perform the business logic of my application, e.g. class FileMaker{ public function makeFile(){ //some code here to make a file } } Now I need to ...
0
votes
1answer
95 views

What is a good practical example demonstrating an architectural advantage in interface dependency injection

I need help (preferably by way of a practical example) to understand why/if the following implementation of IoC/DI (in this case using Ninject) provides an architectural advantage: using (IKernel ...
1
vote
3answers
299 views

Potential abuse of observer pattern

I have a MeetingRoom object that contains a list of Employees, there is a function on each employee called SetMeetingDate, this method has to take into account the state of all other employees in the ...
0
votes
3answers
201 views

Check a boolean before setting it in a loop, or just set it

I have a rather tight loop with the following check to see if balance had ever been positive: balance_null = True while (crazy_loop()): ... if 0.0 < balance: balance_null = False ...