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

learn more… | top users | synonyms (1)

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; ...
2
votes
2answers
176 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
305 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 ...
3
votes
1answer
125 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 ...
1
vote
1answer
127 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(); ...
-2
votes
2answers
166 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. ...
14
votes
3answers
487 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
247 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 ...
6
votes
5answers
1k views

Does this code solve the square/rectangle Liskov Substution Principle example?

I just wanted to check that I understand the LSP correctly and can solve it. I am taking the classic rectangle/square problem and attempting a solution: class Rectangle{ public $width; ...
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 ...
3
votes
3answers
144 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 ...
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
2answers
103 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
2answers
393 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
209 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
214 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
115 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 ...
3
votes
5answers
668 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
98 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
177 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
140 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
534 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
993 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
309 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
61 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
197 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
260 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
267 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
522 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
179 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
100 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
67 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
392 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
97 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
116 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
85 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
252 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
95 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
287 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
270 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
110 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
300 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
243 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
223 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 ...