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

learn more… | top users | synonyms (1)

0
votes
0answers
10 views

How to design DataMapper for table with composite primary key?

Normally I would have a UserMapper that handles a table with a primary key with the following methods: findAll() findByIdentifier($identifier) findByEmail($email) But how would it be for mappers ...
2
votes
2answers
61 views

Best approach for multilingual Java Enum

I'm running into issues with an approach I am taking and am now wondering if I just started down the wrong path and should rethink my approach. Here is what I attempting. I would like to use an Enum ...
1
vote
0answers
65 views

When should something be a class? And are my chosen classes good OO design?

My background: I am new to programming. Python is my only programming knowledge. I program as a hobby, and I'm teaching myself by reading copious amounts of books. I understand enough about OOP to ...
-2
votes
0answers
44 views

What is the best way to call overloaded functions? [on hold]

What is the best way to call overloaded functions? Which one of these is the better coding practice? This question does not refer all the following methods. -Back links, only previous methods are ...
0
votes
0answers
54 views

The finer points of HMVC

I'm new to HMVC and whilst tutorials are great about dealing with the overall details of keeping modules separate and only letting controllers communicate, they aren't so great at explaining the ...
0
votes
1answer
100 views

Are CRUD operations intended to be used with collections?

CRUD operations, by definition are... interfaces that permit users to create, remove, modify or retrieve data Implementations of CRUD interfaces can come in various shapes and sometimes they are ...
7
votes
1answer
142 views

Is this a valid design pattern for a Haskell main function?

After developing several Haskell applications I've found myself rigorously segregating impure code and failable (partial) functions from their pure & total counterparts. These efforts have ...
0
votes
0answers
33 views

Efficiently extracting data from pdf with a template system?

basically allow a user to label specific text in a pdf file. Use the label information to create a template, which a script uses to extract text from specific pdf. What would be a good pattern to use ...
3
votes
2answers
124 views

To subclass or to wrap for “default” implementation?

I'm creating a toolset in Java consisting of many Natural Language Processing (NLP) tools, such as Tokenizer, POS tagger, Lemmatizer, Sentence parsing, etc. I want to put all good and publicly ...
-2
votes
0answers
62 views

Adding if else in better way [closed]

I have one old foundation for server connetcion class in my application. Now I got one new requirement to check if server name contains ### then change calling mechanism by adding parameters to it. ...
2
votes
1answer
78 views

Should this interpretation happen in the Controller or the Model?

Imagine an application where the user is allowed to create his/her own musical scales. The user selects notes from a list, arranges them to a group and presses a button to create the scale. In an MVC ...
2
votes
2answers
90 views

What is a good design pattern to implement REST services on mobile?

It is easy to implement calls to API endpoints, then to parse JSON and handle the data - but what is a good design pattern for this? Here are some ways I have tried but I feel like there should be a ...
2
votes
1answer
40 views

Questions about UML in relation to the command pattern

http://www.oodesign.com/command-pattern.html In reading through a tutorial about the command pattern, I came across a UML diagram that seems to omit some relationships. For the following diagram, the ...
0
votes
1answer
106 views

Design pattern for modifying state and notifying the other modifiers without a loop

The idea is that I have a set of properties that represent possible options in the app. These options can be modified through a variety of different ways, such as from the UI, remotely, third party, ...
4
votes
2answers
253 views

dealing with a very large state machine in a class

I am currently implementing a class for a network protocol. The protocol uses a quite complex and extensive finite state machine. A pair of an event plus a state is mapped to a function, which does ...
0
votes
2answers
125 views

Design RESTful API to update a resource that belong to another resource [closed]

I'm developing an ASP.NET MVC Web Api with C#. I have the following two resources. Group: public class Group { public int GroupId { get; set; } public string GroupName { get; set; } ...
1
vote
1answer
119 views

Should the Presenter depend on the View or the vice versa?

So far, I have used the MVP architecture pattern a few times. Every now and then, I wonder whether my Presenter should depend on my View or vice versa, that is the View depends on my Presenter. NOTE ...
1
vote
0answers
158 views

Client side web application architecture - best practice & patterns [duplicate]

I'm inheriting some code that takes a rather different approach to architecture than I'd have chosen myself. It consists of a HTML page, some javascript library imports and a single DIV tag. This ...
0
votes
5answers
340 views

Liskov Substitution and SRP Principle violation - how best to structure this scenario?

While learning SRP and LSP, I'm trying to improve the design of my code to comply best with both of these principles. I have an employee class that has a calculatePay method on it. Firstly, I believe ...
3
votes
2answers
184 views

What is the difference between a function and a component?

I just listened to Software engineering Radio podcast on components. Their description of components were very vague, they made them sound like lower level versions of functions. I am trying to figure ...
0
votes
0answers
44 views

ZeroMQ and Majordomo protocol

I am learning ZeroMQ and came across the Majordomo Protocol. I am wondering if I'm understanding this correctly, is the use case the same as.. for example.. the Microsoft Azure AppFabric service? ...
2
votes
1answer
110 views

Using the command pattern for a sequence of tasks

I have a 'sequence of tasks' to undertake on a zip file. It can be simplified into these steps: Validate that the file is a ZIP file and is valid Unzip the file Validate the contents are as ...
1
vote
0answers
99 views

How can I put multiple hierarchical forms in a single web page and avoid making it a mess?

We are a group of developers working on a web application that accepts forms filled and sent by our users and present it in an overall view. Our main form view looks like this: There are multiple ...
8
votes
2answers
411 views

What is a good design pattern for generating an Excel (xlsx) file in code?

See my Update at the bottom for more. I occasionally have projects where I have to output some data as an Excel file (xlsx format). The process is usually: User clicks some buttons in my ...
1
vote
1answer
131 views

In MVC design, do I use a base class over an interface?

In web MVC most designs I've seen, (just choosing model layer as an example) the domain problem class, say students, always inherits the superclass "Model." The name is irrelevant, but why do they ...
0
votes
2answers
72 views

Possible design patterns for base function with possible additions

I have various interfaces i have to implement. Let's assume ITypeA, ITypeB. They have following methods: ITypeA Connect Disconnect GetData SetData ClearData ITypeB Connect Disconnect ...
1
vote
2answers
135 views

How to let the outside world decorate my private field?

Imagine a simple Controller (as in process control) interface. I have some concrete classes, say PIDController, that implement it. I also have some decorator classes that extend these classes ...
3
votes
1answer
174 views

Redundancy caused by polymorphism

I have two chat rooms, one has administration behaviour, and one doesn't. I have factored out all of the common code into a base chat room, but the AdministerChatroom behaviour I have pulled out into ...
3
votes
2answers
340 views

What are the disadvantages of a “simple factory”?

I am reading the book »Head First Design Patterns« from O'Reilly. Before explaining the Factory Method Pattern, they introduce a Simple Factory first. They are using the example of a pizzeria. In a ...
0
votes
1answer
296 views

Does this function do one thing only?

Is the following method considered to be doing one thing only? I'm wondering about that since it takes an optional argument. public function findErrors($name = null) { if ($name) { ...
0
votes
0answers
24 views

Pitfalls of combining dependant traits and exceptions in same file as interface in php

What are the potential pitfalls of combining related class like objects (interfaces, traits, custom exceptions) in the same source file? For code reuse and only loading what I need I always separate ...
1
vote
2answers
90 views

Are there any downsides to replacing js confirm boxes with “mark record as deleted”?

I believe in the user experience of always having a confirm pop-up for deletions. However (though we're very used to it), a separate small pop-up window is not ideal and for users on different ...
0
votes
1answer
49 views

The ViewController design in iOS vs MVC in tradiational web apps design

As I came from the background of webapps and move to iOS programming, I am wondering why we can't just apply the MVC design approach to native apps, i.e. in iOS, the view and controller are tightly ...
1
vote
0answers
102 views

Why should ViewModel route actions to Controller when using the MVCVM pattern?

When reading examples across the Internet (including the MSDN reference) I have found that code examples are all doing the following type of thing: public class FooViewModel : BaseViewModel { ...
4
votes
5answers
378 views

Questioning one of the arguments for dependency injection: Why is creating an object graph hard?

Dependency injection frameworks like Google Guice give the following motivation for their usage (source): To construct an object, you first build its dependencies. But to build each dependency, ...
3
votes
1answer
88 views

Augmenting functionality of subclasses without code duplication in C++

I have to add common functionality to some classes that share the same superclass, preferably without bloating the superclass. The simplified inheritance chain looks like this: Element -> ...
2
votes
1answer
84 views

Finding a way to simplify complex queries on legacy application

I am working with an existing application built on Rails 3.1/MySql with much of the work taking place in a JavaScript interface, although the actual platforms are not tremendously relevant here, ...
2
votes
1answer
107 views

Is there a pattern or best practice for passing a reference type to multiple classes vs a static class?

My .NET application creates HTML files, and as such, the structure looks like variable myData BuildHomePage() variable graph = new BuildGraphPage(myData) variable table = BuildTablePage(myData) ...
3
votes
1answer
148 views

Project structure: where to put business logic

First of all, I'm not asking where does business logic belong. This has been asked before and most answers I've read agree in that it belongs in the model: Where to put business logic in MVC design? ...
6
votes
2answers
183 views

Is this a valid implementation of the repository pattern?

I've been reading up about the repository pattern, with a view to implementing it in my own application. Almost all examples I've found on the internet use some kind of existing framework rather than ...
0
votes
3answers
137 views

How to change the state of a singleton in runtime

Consider I am going to write a simple file based logger AppLogger to be used in my apps, ideally it should be a singleton so I can call it via public class AppLogger { public static String file = ...
0
votes
1answer
149 views

Should I limit my type name suffix vocabulary when using OOP?

My co-workers tend to think that it is better to limit non-domain type suffixes to a small fixed set of OOP-pattern inspired words, e.g.: *Service *Repository *Factory *Manager *Provider I believe ...
1
vote
1answer
168 views

Design for object with optional and modifiable attributtes?

I've been using the Builder pattern to create objects with a large number of attributes, where most of them are optional. But up until now, I've defined them as final, as recommended by Joshua Block ...
-2
votes
1answer
53 views

Common phrases to know which resources are no longer available [closed]

I'm working on an script for tracking urls on a web page. This script runs daily to identify resources that are no longer available. If a page returns a status code like 404 I know the resource is ...
9
votes
4answers
438 views

Are first-class functions a substitute for the Strategy pattern?

The Strategy design pattern is often regarded as a substitute for first-class functions in languages that lack them. So for example say you wanted to pass functionality into an object. In Java you'd ...
0
votes
3answers
173 views

Drawback of using static method [duplicate]

For methods that never access instance variable or static variable and they act just like a function (name-spaced) and they are deterministic base on only the input arguments , I want to ask, are ...
3
votes
2answers
350 views

How to layer if statements when order of logic is irrelevant?

Basically I have a series of logic in my website that can lead to 5 total outcomes. Basically two different if tests and then a catch all else statement. For example: if cond1: if mod1: ...
0
votes
1answer
136 views

Best Practices For Temporary Scripts (Python)

I am running two separate programs which are similar enough that they share a lot of code. I run these programs often and after I evaluate the output. This is a very fluid process and everytime is ...
1
vote
0answers
60 views

Dealing with class optional dependencies

I am wondering how are you guys handling an optional class properties. Let's say I have a product that can bud doesn't have to have a color property. Is that really the best way of doing that? Should ...
4
votes
1answer
87 views

JS design pattern/algorithm for avoiding duplicate redraws in a fairly coupled system

Given: some sort of widget based web app lots of JS functionality high coupling (communication/callbacks between widgets) widgets draw themselves certain widgets need to do a complete and fairly ...