Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions tagged [design-patterns]

A design pattern is a general reusable solution to a commonly occurring problem in software design. Use this tag for questions when you're having problems with the implementation of design-patterns. Please don't use this tag on questions about text pattern matching. When using this tag on ...

1
vote
3answers
40 views

What is the best way to set this class's member variable with a value from a .properties file?

I have several entity classes (using Spring) that also have "helper" classes associated with them that offer additional functionality. A very simplified example: public class Contact { private ...
0
votes
1answer
18 views

CSS Design System - How do you handle anomalies?

I'm thinking of making a CSS design system which includes classes like .text-red {color: red} However, I have one question I can't solve, how do you handle anomalies (one of events). A common ...
0
votes
0answers
27 views

How to provide an own instance per variable to each thread (avoid sharing the heap in multi-threading)?

My app builds a complex model based on socket input. Assume that the input comes regularly at two different time intervals, in a hourly interval and in a daily interval. The data is treated exactly ...
0
votes
1answer
42 views

What design pattern do I need for a single object which can receive data from different sources?

I'm trying to create some code in Swift that will enable the following functionality. There is a single class (call it the Datastore) that is the main interface into the code - this is what most users ...
110
votes
4answers
11k views

Avoiding if statement inside a for loop?

I have a class called Writer that has a function writeVector like so: void Drawer::writeVector(vector<T> vec, bool index=true) { for (unsigned int i = 0; i < vec.size(); i++) { ...
1
vote
0answers
19 views

How to manage multiple views in a single page with JavaScript?

I am developing a single page application and trying to grasp MVC, MV* structure with vanilla JavaScript. At the moment I have a page that includes a lot of functionality and events. There are some ...
12
votes
2answers
3k views

What's the difference between Red/Black deployment and Blue/Green Deployment?

I've heard both used to describe the idea of deploying an update on new machines while keeping old machines active, ready to rollback if an issue occurs. I've also heard it used to describe sharing ...
72
votes
9answers
60k views

Singleton pattern in nodejs - is it needed?

I recently came across this article on how to write a singleton in Node.js. I know the documentation of require states that: Modules are cached after the first time they are loaded. Multiple calls ...
1
vote
1answer
14 views

Best way to design: A Thread Class listening for messages and modifyng attributes of a main class

Example: class Car { Car[] otherCars; MsgHandler listeningThread; } class MsgHandler{ Thread t; } The idea its that the MsgHandler when receiving a message, if its matches certain ...
8
votes
3answers
10k views

Clearing/resetting a model in qt (removing all rows)

I'm confused about what the correct way to reset or clear the data in associated with a QAbstractItemModel?. I'm writing an application in which the user can "start over" with a new set of data (...
0
votes
1answer
14 views

Stateful Strategy with Layout Mangager

I try to understand the difference between stateless and stateful. As an example i take the Java LayoutManager. Normally i cannot use an instance for example of the BorderLayout for more than one ...
2
votes
2answers
37 views

create 2 vectors from 1 in R

I am using base R trying to split the following character string into 2: some_text | number1 (number2) | number1 (number2) | number1 (number2) vec1 <- number1 number1 number1 vec2 <- number2 ...
0
votes
1answer
19 views

Accessing the remote class method to resolve cyclic dependency

I am working with multimodule maven project, where I am facing the cyclic dependency between the driver(module A) and actors(module B) Actors module has a common creation of actor system which ...
2
votes
1answer
53 views

How to avoid Method Overloading in Java to avoid duplicates?

I have 2 method which performs 80% same work but differ in result processing. I am doing : private <T> T getResponse(final RestURI query, final Class<T> responseClass) throws IOException ...
1
vote
1answer
53 views

c++ base class called but returning derived class

Before all, I am tied to C++98, how I wish our supplier (and their supplier) would update I am working with a 3rd party framework from which I do have sources. I do not want to change the sources to ...
-1
votes
0answers
12 views

How to properly extend Clean Architecture entities?

I am trying to use Clean Architecture on my Android app project. I was still trying to grasp all the concepts but I think I got most of the basics down. However there are still specifics that I can't ...
0
votes
0answers
13 views

How to design structured logging?

My web app generate log entries on hooks such as model.save. Right now, I have a class Entry (representing a log entry) with a string field content to contain the text of the log entry. Examples of ...
0
votes
0answers
22 views

Structure/Design Patterns for Java parsing program with multiple input combinations based on 2 parameters but one single possible output type

I am writing a tool which takes a file as an input. The input file may be one of these types: "xml", "xlsx", "csv". The file contents will be records of either type "A", "B', or "C". Regardless of ...
-3
votes
0answers
23 views

Asp core architecture [on hold]

I am planning to develop an application using asp core web api2 (using entity framework).In future I should be able to consume api in mobile app also.so can anyone suggest me best design pattern or ...
0
votes
1answer
40 views

code readability / habitual practice / design pattern?

I have been analyzing some classes that can be sumarized like this: public class RulerFather { private Girl girl; private Pet pet; public RulerFather() { girl = new Girl(...
-1
votes
1answer
169 views

Wait for asynchronous GETs to complete in Javascript/JQuery

I'm fully aware that async: false is deprecated with XMLHttpRequest, but the following code meets my immediate need to GET all pages before a subsequent task iterates over them. for (i=0; i <= ...
1
vote
1answer
32 views

Where to put create model and association logic in rails?

I have a model A with some association to B via a join table AB. In the create action for the A controller I create the join model if the optional params are present for the association, otherwise ...
1
vote
2answers
35 views

What design pattern should be used for a workflow like this?

Let's say I have a workflow like this (1) Check for latest commit in a GitHub repo | | (2) Is new commit? ...
0
votes
0answers
18 views

Laravel repository testing

I'm having some trouble understanding what to test and how to do it properly. Scenario: A user is going to make a request to fetch a paginated collection of users. The user only has access to view ...
1
vote
1answer
28 views

Dynamic message “routing” pattern?

We are building an application using microservices and AWS SQS for messaging. We have a requirement for a single message to be handled by multiple microservices before being processed at a "final ...
948
votes
13answers
159k views

Naming Classes - How to avoid calling everything a “<WhatEver>Manager”? [closed]

A long time ago I have read an article (I believe a blog entry) which put me on the "right" track on naming objects: Be very very scrupulous about naming things in your program. For example if my ...
0
votes
1answer
30 views

Does it make sense to use generic parameters to select which service implementation will be injected?

I have a class called ReportWorkflow<TReport> that calls some objects to generate a report of a specific type, the object are always called in the same sequence and the only true difference is ...
4
votes
3answers
469 views

How to avoid short-circuited evaluation in JavaScript?

I need to execute both sides of an && statement, but this won't happen if the first part returns false. Example: function doSomething(x) { console.log(x); } function checkSomething(x) { ...
1
vote
1answer
20 views

Is there a connection between the MVC model and the Bridge design pattern?

I tried looking into the Bridge design pattern, and stumbled upon various answers online. Eventually, I think I got the hang of it. Feel free to correct me if I'm wrong about this, but I could use the ...
0
votes
1answer
45 views

when should i use creational design Pattern? [duplicate]

Creational design patterns are concerned with the way of creating objects. These design patterns are used when a decision must be made at the time of instantiation of a class (i.e. creating an object ...
0
votes
3answers
64 views

An issue with designing my interfaces in C# : Sample Project

I have a problem with designing my interfaces I have these interfaces : interface IField { } interface IScreenField : IField { } interface ITable { CustomCollection<IField> ...
0
votes
0answers
22 views

Designing code to handle specific error messages processed by a generic function

I am a beginner in Python, but I have referred several questions related to individually handling error messages in Python and I've also read best practices of raising exceptions. However, this is ...
0
votes
2answers
27 views

How to use regex to limit domains?

I'm making an html5 form and only want users to sign up with .edu or .gov email addresses. What would the regex look like for that? I know it must be checked serverside as well, but one step at a time....
62
votes
19answers
33k views

Why do we need immutable class?

I am unable to get what are the scenarios where we need an immutable class. Have you ever faced any such requirement? or can you please give us any real example where we should use this pattern.
0
votes
1answer
23 views

Should I refer to an instance or a class method in a loop that creates objects?

I am working on importing a .csv file into a Ruby on Rails app. The importer will create a new database record from each row of the file. class Invoice < ApplicationRecord def self.import(file) ...
0
votes
1answer
25 views

An entity that associated to multiple entities

I have multiple entities like so: Public class User{ int age; . . . @OneToMany private Set<Comment> comments = new HashSet<>(); } and Public class Product{ ...
0
votes
1answer
65 views

I have an issue with implementing my Interfaces with c# [on hold]

I have a problem with designing my interfaces I have these interfaces : IField IScreenField //this interface inherit from IField CustomCollection<IField> AnotherCustomCollection<...
1
vote
0answers
43 views

Create a subclass whose superclass is known only when it is being created

Problem I want a convenient way to create a widget that has a QHBoxLayout or QVBoxLayout as its layout. The type of the widget could be any container widget unknown initially and but specified upon ...
-1
votes
0answers
18 views

Architecture of a Web-app, is there any better choice? [on hold]

consider a scenario: For 1000 store branches that need web-based solution (receive data at first use from server and put it locally and after that use minor central update and save sold product list ...
2
votes
4answers
195 views

Composite pattern with variations in classes

I have a situation where class A, B, and C, all are derived from X to make a composite pattern. Now A, B, and C are very similar but they do have different internal attributes. My question is how do ...
39
votes
5answers
11k views

Strategy Pattern V/S Decorator Pattern

I just came across two patterns. Strategy Pattern Decorator Strategy Pattern :- Strategy pattern gives several algorithms that can be used to perform particular operation or task. ...
0
votes
1answer
42 views

Is there a pattern to force the setting of a property in an injected component?

I am wondering if there is a pattern that forces the user of my component to set a property after it is autowired. For example i have this: @SpringComponent @PrototypeScope public class ...
1
vote
1answer
40 views

FlyWeight Design Pattern

I was Going through an example of flyweight Pattern i found online. import java.util.Random; import java.util.HashMap; // A common interface for all players interface Player { public void ...
0
votes
0answers
26 views

Developing a website with ability to convert to mobile application [on hold]

I'm preparing to develop this website as a personal project that I've been thinking about for a long time, I'm using the ASP.NET MVC framework. but I want to think ahead of time and develop my website ...
0
votes
1answer
55 views

Which design pattern is applied when implementing the methods of Temporal

In the date and time package java.time, the methods, especially the plus(TemporalAmount amount) and minus(TemporalAmount amount), in the interface Temporal are implemented in LocalDate, LocalTime, and ...
-2
votes
1answer
29 views

Can I use abstract class (that implements interface) in designing a high level class diagram

Can I use abstract class (that implements interface) in designing a class diagram? My lead points what if someone uses interface directly? and he suggests design should stick to interface and classes? ...
59
votes
9answers
31k views

Sequencing ajax requests

I find I sometimes need to iterate some collection and make an ajax call for each element. I want each call to return before moving to the next element so that I don't blast the server with requests - ...
-2
votes
1answer
39 views

I'm having trouble understanding SOLID principles

I could really use some help with this one. I'm trying to use SOLID principles in my next php project but i'm having a really tough time understading it. First of all, i can't really grasp single ...
2
votes
1answer
62 views

Golang Transactional API design

I'm trying to follow Clean Architecture using Go. The application is a simple image management application. I'm wondering how to best design the interfaces for my Repository layer. I don't want to ...
25
votes
8answers
16k views

How to abstract a singleton class?

This is how I write my singleton classes. public class MyClass { /// <summary> /// Singleton /// </summary> private static MyClass instance; /// <summary> //...