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

learn more… | top users | synonyms (1)

5
votes
5answers
326 views

Can a pimpl variation be implemented without any performance penalty?

One of the issues of pimpl is the performance penalty of using it (additional memory allocation, non-contiguous data members, additional indirections, etc..). I would like to propose a variation on ...
-1
votes
1answer
165 views

What is the difference between Adapter and Delegation design pattern?

I am very confused about Adapter and Delegation design pattern. In Adapter pattern we bring an intermediate class to interact with another class. And in Delegation pattern we also bring an ...
2
votes
2answers
260 views

Java Game. Preload objects and reuse vs create objects at runtime [closed]

I'm currently developing my first game in Java language. The game is an endless runner with obstacles to avoid and enemies to kill. Unfortunatelly im still not experience enough and many times im ...
2
votes
1answer
140 views

What is the alternative design pattern of a state machine that may have recursive state change?

I have a state machine like code, which has state A,B and C, with a function changeState(char i) which can change the state of a system, and each state can also call changeState(char i) to switch the ...
12
votes
3answers
7k views

What is a helper? Is it a design pattern? Is it an algorithm?

Maybe a little tongue-in-cheek, but as I can't find this answer anywhere through Google, so to ensure Programmers Stackexchange has the answer: What is a helper? I see the name being used everywhere ...
16
votes
3answers
1k views

Legitimate “real work” in a constructor?

I am working on a design, but keep hitting a roadblock. I have a particular class (ModelDef) that is essentially the owner of a complex node tree built by parsing an XML schema (think DOM). I want to ...
5
votes
4answers
283 views

Object with Customized Properties and Methods

A project I am working on currently models Order information. Right now, there is one class with a bunch of properties and functions that all of orders have in common. In addition, some of our users ...
25
votes
1answer
1k views

Is “StringBuilder” an application of the Builder Design Pattern?

Is the "Builder" pattern restricted to addressing the "telescoping constructor" anti-pattern, or can it be said to also address the more general problem of complicated creation of immutable objects? ...
4
votes
3answers
408 views

Avoiding constructors with many arguments

So I have a factory which creates objects of different classes. The possible classes are all derived from an abstract ancestor. The factory has a configuration file (JSON syntax) and decides which ...
2
votes
3answers
184 views

What is the purpose of a wrapper class that does nothing but delegate to the object it wraps?

The specific example I have in mind is javax.servlet.ServletResponseWrapper: public class ServletResponseWrapper implements ServletResponse { private ServletResponse response; /** * The ...
6
votes
1answer
186 views

Which is the preferable design for my Gateway? [closed]

I'm writing a Gateway class that extracts information from a HTML document. One of the responsibilities of the class is to traverse a table in the document and extract data from its rows. I'm trying ...
9
votes
2answers
2k views

Observer pattern over HTTP and TCP/IP (Server-Client)

I have a server and many clients (around 50 clients) who connect to that server based on a web application, which is of course based on HTTP protocol, which in turn uses TCP/IP (correct me if I'm ...
2
votes
1answer
123 views

Design Pattern for Library Wrapping Extern Methods

I am working to create a C# library that wraps a C DLL to integrate with our test system. The C DLL has probably close to 100 functions that can be accessed and all from the same DLL. I don't need ...
5
votes
2answers
195 views

Factories, vectors and smart pointers - Design Question

So, my Business Code needs some Objects. It does not know how much objects it needs and it does not know the exact types (because polymorphism is involved). For me, that sounds for a good reason to go ...
3
votes
3answers
112 views

Relational table design for data ownership

Setup (schema simplified for clarity) Suppose I have a table called resource: +---------------+--------------+------+-----+ | Field | Type | Null | Key | ...
5
votes
1answer
172 views

Call base inside overriden method

I know there are questions about calling the base method inside an overridden method such as this. But what if an overridden method only calls the base class? Is this bad/good deign? It just seems ...
2
votes
1answer
76 views

How to get the behavior class from its data class when they are separated for the purpose of server-client communication?

I am writing a server-client program with the following idea (analogy for my real program). There are many types of shapes. The client represents the shapes to the user which can queue operations ...
3
votes
1answer
132 views

Minimizing lock time (multithreaded app)

I have a web application written in C# which uses external dll written in C++. Communication between clients (web browsers) and a web application is done using SignalR. For communication between web ...
3
votes
1answer
109 views

Single Responsibility Principle : Proxy Pattern for refactoring

However, in cases where the tests did not force the separation, and the smells of Rigidity and Fragility become strong, the design should be refactored using the Facade or Proxy patterns to ...
7
votes
1answer
188 views

Is event sourcing only for when writes are rare?

I'm reading up on event sourcing and can't stop asking myself if it only makes sense in exotic situations where writes are very rare or military-grade auditing is required. A non-exceptional system ...
1
vote
2answers
205 views

Dealing with an often occuring dependency that is not related to the class

I'm using view classes for my templating. These view classes often require the Routing class to get URI's from other pages. You could actually say that the Routing should be available to every view ...
-1
votes
2answers
560 views

Where and how to reference composite MVP components?

I am learning about the MVP (Model-View-Presenter) Passive View flavour of MVC. I intend to expose events from view interfaces rather than using the observer pattern to remove explicit coupling with ...
37
votes
9answers
3k views

Using compound statements (“{” … “}” blocks) to enforce variable locality [duplicate]

Introduction Many "C-like" programming languages use compound statements (code blocks specified with "{" and "}") to define a variables scope. Here is a simple example. for (int i = 0; i < 100; ...
4
votes
2answers
336 views

Design pattern for mapping data fields

I have seen this problem a few times and never can come up with a solution i like. System A Sales Order Entity order_id created line_items_count System B Sales Order ...
4
votes
3answers
225 views

Alternatives to Singletons for caching lists of data?

In my project, I have an abstract Cache class that allows me to populate a series of lists that globally persist throughout my application. These cache objects are thread-safe and can be manipulated ...
-2
votes
1answer
148 views

Is there a pattern to map a range of numbers to a string?

I need a function that will take the name of a town and return a specific range of numbers that is assigned to that town. I won't be using a database. The simplest way to do this is //Pseudocode ...
1
vote
3answers
142 views

How To Extend Parent Methods in Children Classes?

There is a parent class with a method which many children use but many children extend the method, what is the best way to extend it without violating DRY? Here are my 2 current solutions: 1: The ...
0
votes
1answer
68 views

Abstract classes with static methods in PHP

Pre: I am looking at a quite big PHP project developed by a company which we need to partly interact with while building a new webapp. The whole application is developed in PHP 5. Most of the ...
0
votes
1answer
182 views

What is the name of this design pattern?

Magento has a class called Varien_Object with a pattern I'm trying to identify. The pattern creates hidden data and allows access to it but the main difference between this and a normal facade is ...
0
votes
2answers
149 views

Tips for working with badly designed software [closed]

Currently in my job im working with a lot of older php systems which don't follow normalised design patterns and are frankly, a mess. As an ethical developer and someone who always strives to better ...
0
votes
1answer
115 views

Could this class be considered as a Factory class? [closed]

I've recently worked on a reusable network service class for a service-aggregator iOS app. This class should retry a failed request if it was caused by expired user token. Plus, this class will be ...
1
vote
1answer
82 views

How to handle multiple “valid after {date}” in a performant way

We work on an Application which displays a duty roster and also some other DateTime related things. So my Database is full of Relations like in this small Example: This results in big ...
4
votes
2answers
296 views

What design pattern best suits managing handles to objects, without passing handles or Manager around?

I'm writing a game in C++ using OpenGL. For those that don't know, with the OpenGL API you make a lot of calls to things like glGenBuffers and glCreateShader etc. These return types of GLuint which ...
0
votes
0answers
48 views

UML Modeling - Creating flexible Pattern Viewer, extending context leads to too much changes

What I'm trying to make with jsp's java and servlets is a web based 'selector' for patterns. Here you can see all the design patterns there are (like www.oodesign.com). But for learning purposes I'd ...
1
vote
1answer
110 views

Extensible way to create bash program

I have a bash script that should be extensible with additional functions with as little change to the script as possible. The basic function is as follows. It loops through a list of files to check. ...
0
votes
1answer
113 views

Should I hold an Id and the Item [duplicate]

Let's say I have a Customer which contains an Address class like: public class Customer { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; ...
1
vote
1answer
147 views

Template method pattern - abstract classes vs interface delegation

Template method pattern is commonly implemented with abstract classes. interface Algorithm { void perform(); } abstract class AlgorithmBase implements Algorithm { abstract void step1(); ...
4
votes
2answers
298 views

How to avoid circular patterns in Node?

I'm new to Node and JavaScript (well, asynchronous programming in general) and I noticed when I was working on a project that the following code is a circular pattern and that these are bad practice ...
2
votes
2answers
180 views

Is there a Factory Pattern distinct from Abstract Factory and Factory Method?

During a recent phone screen I was asked to describe the "Factory Pattern". I asked if the screener meant "Factory Method" or "Abstract Factory". He said, "No, just the Factory Pattern". I don't know ...
0
votes
3answers
337 views

Is this 'implementation' of a builder pattern good design

public class MyButton{ public MyButton(){} public MyButton setIcon(Icon icon){return this;} public MyButton setText(String text){return this;} } And used like: MyButton testButton = new ...
5
votes
1answer
125 views

Strategies to increasing the maintainability of assertions in code [closed]

Background I am writing a compiler for a custom language for a school project and it is going really well for me. If I where to start all over from scratch I would have done many software ...
14
votes
3answers
505 views

Patterns for passing context through a method chain

This is a design decision that appears to come up quite a lot: how to pass context through a method that doesn't need it to a method that does. Is there a right answer or does it depend on the ...
1
vote
3answers
270 views

Factory of factories? [closed]

I have concrete factory classes which implement MyFactory interface. I want to get concrete factory objects based on parameter. How to do this? One way is to create factory of factories[FoF], and ...
-2
votes
2answers
167 views

Avoid copy and paste programming, what pattern to use? [closed]

I have a small software that generates some Word documents. It reads a template, runs a few SqL procedures to get the data, generates the documents and then sends them via e-mail. It's quite simple. ...
1
vote
2answers
106 views

How to mitigate complexity of fallbacks introduced to automatically retry upon failure?

So this may come off a bit broad and generalized, but after spending some time working around under developers, I've come to notice many different methods and design patterns. However, one big thing ...
4
votes
5answers
776 views

Does the Factory Pattern violate the Open/Closed Principle?

Why does this ShapeFactory use conditional statements to determine what object to instantiate. Dont we have to modify ShapeFactory if we want to add other classes in the future? Why doesnt this ...
1
vote
1answer
83 views

Possible design patterns for a service that synchronizes two third party services [closed]

I am currently in the process of refactoring a web service that synchronizes two third party services. The two services do not really interact well with each other, and there is quite a bit of ...
2
votes
1answer
59 views

Is it a good practice to separate lower level code from ReactiveX

Consider I have a Calculator class, it calculates an Integer. On higher parts of the system, say a MVP presenter, I want to work with an ReactiveX Observable that emits the Integer. I could do the ...
1
vote
3answers
213 views

Why do we need a context class in strategy pattern?

For the strategy pattern, why do we need a context class to call the appropriate algorithm? Why cant we just do Strategy s=new OperationAdd()? This way we still use polymorphism.
3
votes
3answers
148 views

Communicating to an Object from another without coupling in java?

So I have a Person object, and a GumballMachine object. The behavior I'm searching for is, in the intent to avoid unnecessary coupling, have the method insertCoin() called from within the Person ...