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

learn more… | top users | synonyms (1)

4
votes
1answer
112 views

Which pattern best describes decoupling file building from output file format?

A common feature we have is a report be available available in multiple formats. For example, a pricing report will be available as an Excel spreadsheet for the marketing team to be able to tweak the ...
0
votes
1answer
128 views

Child classes only change some “options” - what's the best approach?

I'm currently implementing functionality in Symfony (PHP - not that it should make any difference which language I'm using) where I have about four controllers that do almost exactly the same thing. ...
1
vote
1answer
63 views

OO Design: Reading/Writing object with multiple formats

I have a class Song, which has the following public methods: String getSong(); void setSong(String); int getId(); void setId(int); Now I have two different ways I might want to store these songs in ...
-4
votes
4answers
301 views

Why aren't named switch statements a language feature? [closed]

I could imagine the below code being somewhat useful. Is there a reason this pattern hasn't made it into programming languages? To be clear the string was just what I chose as an example you could ...
2
votes
2answers
251 views

What is the role of the public folder in MVC web applications? [closed]

Must all the controllers, models and views be placed in the private folders? If so, what are the roles of the public folder? What are the correct terminologies for such roles in computer science? How ...
0
votes
1answer
225 views

Rich Model vs God Class [duplicate]

I have a legacy code containing some behaviour classes, like services and controllers. My model is pretty anaemic. It's just a repository of getters and setters, and I want to refactor it. There is a ...
2
votes
4answers
238 views

Reusing the logic in another repository in ASP.NET MVC repository pattern

I have an ASP.NET MVC4 web application, with EntityFramework for data access. In the application I have two repositories as follow (this is only an example not my real code): public class ...
0
votes
1answer
77 views

How to split a class that is an implementation of interface?

Let's say there is class called AccountingService. Using this class I fetch all kinds of ecommerce records like products, customers, etc. The fetching happens inside a controller action. Once fetched, ...
2
votes
3answers
191 views

Design pattern for large amounts of overflowing data?

Our current queues publish messages that consumed by 3rd party services with rate limits. Currently the messages are retried with exponential back-off. However there could be cases where data is ...
0
votes
1answer
333 views

MVC Best practice mixing Partial View and JavaScript

I searched the internet and really can't find a good answer to this question. Imagine there is a View that contains a simple tab-element. Each tab-content is loaded dynamically (via ajax) when the ...
0
votes
0answers
82 views

Ruby best practices for Data Access layers

I'm starting my way into Ruby development and have some questions that I hope you can give your best opinion to better design some command line applications I'm developing. What are the best patterns ...
0
votes
1answer
84 views

Simple explanation of MVC needed [duplicate]

I am trying to understand MVC, but for most of the Q&A's I have seen, the description is great but I cannot quite understand it, I think it works like this scenario I thought of: User ...
0
votes
1answer
65 views

Parsing an object from multiple source files

I receive zip files and they have as content 8 different files, each with it's own metadata inside. I have to combine these files into 1 object containing certain metadata. The big issue here is that ...
1
vote
1answer
75 views

What pattern should one use for multiple interpretations of the same data?

I have a set information that I am able to read in as raw data which corresponds to different physical quantities depending on which device provided that information. Every device contains the same ...
3
votes
5answers
1k views

When are enums NOT a code smell?

Dilemma I've been reading a lot of best practice books about object oriented practices, and almost every book I've read had a part where they say that enums are a code smell. I think they've missed ...
0
votes
1answer
80 views

Dynamic query from view layer

In my current job they are defining a new corporate architecture for java development. It is something like this: ProjectView: JSF view layer. Uses delegates on the ProjectClient layer. ...
1
vote
2answers
185 views

Design of an online book reader

I want to design an online book reader system as a programming exercise. I wrote down the following requirements: Searching a book by title. Bookmarking a book. Mark a book as favorite. Give rating. ...
0
votes
0answers
88 views

How to improve the design pattern of this Screen Window system?

I have a Screen Window system, a Screen (IScreen as interface), which holds a window, either WindowA or WindowB. System can switch window by calling stateChanged: class IScreen{ public: virtual ...
4
votes
3answers
364 views

Name of this pattern to wrap functionality

I have a system that allows certain functionality to be implemented different ways, but requires that the functionality of each implementing class be wrapped in another layer. For example, each ...
2
votes
2answers
74 views

Design architecture advice on relation between objects and singleton JS

I would like your feedback regarding some best practices on design relationship between objects, specially when a singleton object is involved. Let's imagine I need to simulate a Shop with ...
0
votes
2answers
167 views

What is the pattern that uses multiple instances rather than multiple classes called? When would I use it?

Sometimes I find it useful to have a single class with multiple instances (configured differently via their properties), rather than multiple classes (inheritance). ??? Pattern Single class (Fruit) ...
1
vote
1answer
156 views

Interface Implementation: A parameter I don't need

Pseudo-Code interface IPagingInfo { int CurrentPageNo { get; } int RowsPerPage { get; } ... } interface ResultsRetriver { ResultRows GetResults(IPagingInfo pagingInfo); } class ...
1
vote
1answer
139 views

Interface Design: Specific vs General parameter (A Minimal design vs anticipated use variation)

Code public interface IVehicle { string VehicleMake { get; } int MonthsSincePurchase { get; } bool IsApprovedUsed { get; } ... } public class WarrantyPopUpHandler { virtual bool ...
7
votes
2answers
2k views

how to refactor many singletons

I have a medium-sized python program (~5000 lines of code), which I've built up over time, with no particular plan as I went ahead. The architecture I've ended up with consists of 5-6 large Singleton ...
8
votes
2answers
521 views

Doesn't dependency injection push the testing burden further down the chain?

I'm learning about dependency injection and while I can see the appeal of it when writing functional libraries, I fail to see how it solves anything when you'll also be the one using the libraries. ...
3
votes
1answer
270 views

What architecture should I use for my game entities?

I am working on my final year project and making a multi player game. It's a tank battle game. In the client basically we will have 2 types of Tank. One will be controllable by the keyboard and ...
0
votes
2answers
359 views

Does algorithm design belong to software engineering? [closed]

In academic meaning, it seems to me that algorithm design is studied in a high/abstract level of computation (computability, complexity), although software engineering is also studied in ...
2
votes
1answer
153 views

Should I use strategy design pattern or something else?

I have recently started reading Heads First Design Pattern Book as well as coding on my final year project. In my project I am having Tanks which extends Entity. A Entity can be anything in the game ...
3
votes
1answer
106 views

Could a view call a function of the model directly?

this is a fundamental question about MVC (in particular using AngularJS) and I've found similar questions here, but not the exact same problem: Could the view call a function of the model, or should ...
0
votes
2answers
202 views

Do we need servant pattern? What about implementing in parent class?

From wikipedia: Servant is used for providing some behavior to a group of classes. Instead of defining that behavior in each class - or when we cannot factor out this behavior in the common ...
2
votes
1answer
164 views

Explain ServiceLocator pattern of ZF2

I am looking at this example: http://framework.zend.com/manual/current/en/user-guide/database-and-models.html Relevant excerpt from above: class AlbumController { public function ...
4
votes
1answer
130 views

How do I use decision tables to prioritize between objects - or should I do something different? [closed]

I have a case similar to this one: Multivariable decisions The difference is, that it's not a single decision I need to make but more like I have a pool of (let's say 10 object) where each object has ...
21
votes
6answers
3k views

Iterator pattern - why is it important to not expose the internal representation?

I am reading C# Design Pattern Essentials. I'm currently reading about the iterator pattern. I fully understand how to implement, but I don't understand the importance or see a use case. In the book ...
3
votes
2answers
361 views

Deep SQL relationships to a C# object model

I have a database with deep table to table relationships for example Clients (one to many) -> ClientData (one to many) -> ClientJob (one to many) -> ClientProcess (one to many) -> ...
29
votes
4answers
4k views

Does C# 6.0's new null-conditional operator go against the Law of Demeter?

The Law of Demeter states the following: Each unit should have only limited knowledge about other units: only units "closely" related to the current unit. Each unit should only talk to its friends; ...
3
votes
3answers
125 views

Deleting a domain object and ensuring any remaining references are subsequently unusable

If I have a domain class with an instance method Delete(). What is the best way to ensure that any leftover references to an instance that has "deleted itself" are subsequently unusable? This ...
0
votes
0answers
100 views

Should I be using a design pattern when creating these objects?

I have a lot of duplicate code in my program that basically follows this structure: If condition is true Create ErrorRecord object Call ThrowTerminatingError(error object) End if The ...
0
votes
1answer
128 views

Best pattern to write a PHP function that checks on access and returns more then boolean?

I'm prototyping behaviour of a new application, and want to write some functions that check on access based on some variable dates. I just want to write separate functions for that, like ...
0
votes
1answer
154 views

Object Communication Design

Multiple top-level systems that communicate with each other via messages(events/commands). The Main class of the program wraps around all the systems and has a message dispacher component wich ...
0
votes
1answer
282 views

Domain Model vs Presentation Model vs General Function

I have been building an app for my company i join for the past > 1 year, we're using Java Spring Hibernate Javascript jQuery Kendo UI And for the structure i can say something like this from ...
2
votes
3answers
148 views

Single responsibility policy problem

I'm a bit stuck using the single responsibility policy. I have a class named Parser, which can be configured to parse input a certain way. For the sake of convenience I will limit the configuration ...
1
vote
4answers
132 views

Should it use counter, or flag inside objects, to indicate progress?

For example, I have a game, it has 5 enemies which attack once sequentially at each round: class Enemy{ }; class Game{ public: Enemy enemys[5]; }; I want something to indicate which enemy has ...
2
votes
1answer
127 views

Observer for two independent events in the observable class

Observer pattern aim: the observer class responds to the changes of the observable class state. Problem. There are different processes inside observable class that should be observed. Those events ...
1
vote
4answers
349 views

What's the alternative to DRY code when it requires too many parameters?

What is the best strategy for maintaining easy to follow code when keeping things DRY means you have to pass a lot of parameters to shared functions? In my specific case, I have a grails based app, ...
5
votes
4answers
448 views

Design pattern for wrapping logging around execution

Introduction I am implementing a abstract Java class of a processing framework*. By implementing the function execute, I am able to add business logical functionality. I would like to add logging at ...
1
vote
1answer
97 views

Stuck on design when attempting to create an object store

I'm working on a small scale API project but as it will be used and maintained by people that are not Software Engineers to trade I am attempting to keep the design as separate and identifiable as ...
4
votes
1answer
130 views

How to represent very specific business logic in classes containing the business logic?

BusinessModel: I have a ice cream shop and I designed classes to do my supplier based financials based on industry types(Lines of business). I sell ice creams of many types, which I buy from different ...
12
votes
3answers
786 views

How to draw programmer's attentions in certain conditions?

Let's start with an example. Let's say, I have a method called export that depends heavily on the DB schema. And by “depends heavily” I mean I know that adding a new column to a certain table often ...
2
votes
0answers
403 views

Assembler vs Entity Translator and Entities vs DTO

I was hoping that someone could explain the exact difference between an Assembler and Entity Translator. Martin Fowler describes the Assembler as a sort of Mapper(?) which converts DTOs into Domain ...
2
votes
1answer
109 views

Does implicit and explicit cast operator overloading violate the D in SOLID principles of OO?

I'm looking at different patterns and techniques for implementing logic to convert object from one class to another, and the most elegant seems to be explicit cast operator overloading (in C#). ...