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

learn more… | top users | synonyms (1)

4
votes
2answers
406 views

What alternatives to a singleton are there for a class which only can have one instance?

I need to represent an abstraction over various parts of the hardware for a game. I'm trying to decouple the code that does things like manage the logic of the game from the code that is API/platform ...
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.
0
votes
2answers
215 views

my software model has some kind of cyclic dependency

I need a recommendation about my software model. I think it is not that good, since there is some kind of cyclic dependency. I have an OSGI bundle under Kura application framework, here are the ...
3
votes
3answers
116 views

Which pattern can I use for doing computations involving similar yet different object subtypes?

How do I design code that has two qualities: uses similar but different subtypes of an object uses similar but different types of computation on the above objects Example I am refactoring this ...
4
votes
5answers
771 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 ...
0
votes
1answer
100 views

What pain point does Intelligent Children Design Pattern solve?

In absence of this pattern, downcasting is needed in the derived classes. My question is does this pattern solve only the problem of downcasting? And why is downcasting bad compared to the alternative ...
5
votes
1answer
96 views

Enclosing main invocation of a function in an if

As a part of my school CS class, I am reading Python Programming by John Zelle. In the book, Zelle talks about surrounding the invocation of a main method with if <condition>: main() ...
2
votes
2answers
183 views

Passing fields (instance variables) by arguments (parameters) inside an object - does it make sense? [duplicate]

I believe this is language agnostic question - if it's not then please correct me. Let's say I have a class (code snippet is a kind of 'pseudo code') class Car: private steering_wheel private ...
3
votes
2answers
142 views

Design review of a small configuration framework [closed]

I want to create a simple configuration framework. Yes I know, there are many frameworks, which make their job very well. But for interesting in architecture, I want to create my own. My framework ...
5
votes
5answers
584 views

Advantages of Strategy Pattern

Why is it beneficial to use the strategy pattern if you can just write your code in if/then cases? For example: I have a taxPayer class, and one of its methods calculates the taxes using different ...
12
votes
4answers
1k views

How does having too many instance variables lead to duplicate code?

According to Refactoring to Patterns: When a class is trying to do too much, it often shows up as too many instance variables. When a class has too many instance variables, duplicated code ...
12
votes
1answer
310 views

Can domain models in the database be a sustainable solution?

I just started at a new job as a database developer for a medium-small sized, company based on Microsoft-technology. I noticed early on how much practices deviate from what I've been taught at school ...
1
vote
1answer
62 views

Converting data in setters in a DTO

I wrote a simple DTO to transfer data from one point to another, or so was the initial thought. Now I just caught myself in the act of doing various things in the DTO, for simplicity's sake, like ...
1
vote
2answers
202 views

The granularity level to repeat code: should downloading, unzipping etc. be handled by separate classes?

I make extensive use of DI, but I wonder, where is the 'granurality' limit, when some set of functionality should be separated to a class - lets take an example: public class DownloadManager : ...
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; ...
2
votes
3answers
285 views

CRUD operations in DDD

I'm designing an application with DDD. I'm moving from flat POCO objects to strong domain models, so my question is: Would I have to call my basic CRUD operations (located in my repository layer) ...
2
votes
2answers
286 views

Can I wrap a collection with a static class and still call it repository pattern?

I couldn't find a single example about repository pattern using something else then a database. My goal is to have a global static repository that stores some objects in memory. I don't want it to ...
9
votes
4answers
523 views

Are there any significant disadvantages to depending upon abstractions?

I was reading this wiki on the Stable Abstractions Principle (SAP). The SAP states that the more stable a package the more abstract it should be. This implies that if a package is less stable (more ...
2
votes
2answers
191 views

Design pattern for fetching data in chunks

I am creating Qt application that uses database with huge amount of data to draw some charts. Fetching data from the database is time consuming, so is blocking the application thread or worker thread ...
1
vote
4answers
107 views

How to design class model for specific products, some of which may contain groups of specific product models

Class Design Question I am trying to figure out a good way to design my class system. I have a class Product to compute various product specifications. I have two product model groups, each ...
1
vote
0answers
68 views

Function behavior dependent on the calling class [closed]

I have a base class B and several children classes of it. Every children B1, B2, B3... has a method that calls a method M of another class C. Class C has a component D (implementing an interface, ...
4
votes
2answers
410 views

What is NOT MVC? (in a web app)

It is easy to find many descriptions of what MVC is - for instance here, here or in this video. I'm curious, what is NOT MVC? or more precisely - In a MVC-using app, what is everything else apart ...
2
votes
1answer
99 views

How to do data modeling when the model is partially initialized from DB?

Consider data modeling in Scala(the other language is the same), we often want to composite one model inside another, e.g a Post may contain an author field whose type is a User. When we retrieve the ...
1
vote
1answer
120 views

The Model or the Controller write data on the view in MVC and what is the use of the Model if we have data in Store?

I've read several articles, watched videos and read questions on here, but the more I read and learn about MVC - including MVCS or MVP in addition.. to make it even worse - the broader the pattern ...
2
votes
3answers
86 views

A pattern to find out if data in a dialog-window was modified by the user?

I think about if there is a pattern or another intelligent solution for that problem. I am searching for a more generalized and reusable solution. I load an existing and still persistent row/object ...
1
vote
3answers
253 views

How is this pattern called?

Is there a name for this pattern where an API offers several variations of a method (differing in number of parameters) and internally forwards them with default parameters like this: public void ...
0
votes
1answer
104 views

Patterns for migration to multi-tenant application [duplicate]

I have a complex web application that manages stores and their customers. The application follows a basic MVC architecture and I should migrate it to a multi-tenant application: - I should go from ...
2
votes
1answer
295 views

Model-View-Controller design question (One vs. multiple models for multiple view+controller)

I have an issue with shared code in a MVC application. Application controllers/views ABC are different classes but use a common framework. It is a single class reused multiple times. Let me introduce ...
4
votes
3answers
289 views

How to avoid the LoadBy pattern?

In our codebase for a sophisticated system controlling many aspects of businesses, we have a certain unwritten law to not fudge around in code with complicated SQL, instead writing it into a function ...
2
votes
3answers
273 views

Use of electronics in programming [closed]

Does a programmer need to have a deep understanding of digital electronics. Theoretical v/s practical. As what they teach us at college is pretty basic? If yes, then do all kinds of programmers ...
4
votes
1answer
115 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
66 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
302 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
282 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
231 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
244 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
87 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
195 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
386 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
90 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
66 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
89 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
187 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
365 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
76 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 ...