Skip to main content

Questions tagged [patterns-and-practices]

Design patterns (repeatable solutions to commonly occurring problems) and best practices in software engineering

Filter by
Sorted by
Tagged with
39 votes
8 answers
10k views

Is it ok copying code from one application to another, both belonging to the same repository, to keep them independent?

Given a repository which contains two different applications A and B (e.g. bootloader and RTOS), is it ok to copy source code from A to B in order to avoid dependencies (include's, adding A source ...
Dan's user avatar
  • 615
1 vote
4 answers
1k views

Pattern / solution for Boolean decision making chains

I need a solution for decision making chain. There are number of criteria that may return true, false or be inconclusive. A non-functional code (Java) would look like this: Boolean res = ...
Dariusz's user avatar
  • 423
6 votes
2 answers
1k views

Is there a term similar to "upsert", but for the "find or create" case? [closed]

I'm wondering if there is a commonly used term similar to "upsert" or "merge" but for the case of "find or create". Ideally with a single word, something shorter that &...
Jbm's user avatar
  • 447
-2 votes
1 answer
139 views

Patterns for multi tenant systems [closed]

Ok so first I want to describe the anti-pattern anti-practice. Company creates system for customer number 1. Then customer number 2 comes along they fork the codebase customize it. (Say for variations ...
DarcyThomas's user avatar
0 votes
2 answers
4k views

Unit testing private methods

preface: I know this topic has been asked about a lot on here in the past. Hopefully I will make it clear that I've read a fair amount of the questions/answers on the topic, and other literature, too. ...
Alexander's user avatar
  • 4,954
1 vote
2 answers
128 views

Adjective for function types on wether the values are received or sent

I don't know how to phrase this better, but I remember reading an article about type theory, that categorized the values being received by a function and the values being sent back from the functions. ...
Antoine Catton's user avatar
1 vote
1 answer
207 views

Writing a SQL recordset as a HTML Table - a bad practice?

I'm maintaining an intranet using ASP Classic. Some of pages looks like one or more HTML tables used for administration tasks. Those tables are obtained by SQL requests. Server side, they are kind of &...
Amessihel's user avatar
  • 137
0 votes
1 answer
112 views

Should a payment success or error page expire?

When payment is made, it either succeeds or fails for whatever reason. In this case, though not important, the payment is made on a third party payment website, like Paypal, and a callback url is ...
Richard's user avatar
  • 113
1 vote
5 answers
2k views

Is this an anti pattern or misusing the interface default method?

Instead of checking the null and throwing exception each time we call findByOrderNumber method, I came up with this pattern by taking advantage of a default method, are there any patterns misused here ...
user3595026's user avatar
1 vote
1 answer
438 views

Object oriented service best practice when changing a methods behavior for given context?

I expect this is a common problem and/or pattern question for beginners to OOP. Somehow I find myself wondering again and wasn't able to find a decent answer. So at the risk of creating a dupe... What ...
ooXei1sh's user avatar
  • 113
-2 votes
1 answer
120 views

Seeking a Pattern [closed]

First off, I totally understand that an interface cannot contain a static method because what would the method act on - that is clear. Suppose I want an interface to mandate a method that is ...
TerrierJack's user avatar
1 vote
2 answers
2k views

Best way for resource (entity) relations loading in a REST API

We have a problem of load time in our REST API, which is the result of having Fat DTO (nested DTO s) & the N+1 problem (which is off my question), means that we are loading too much data in one ...
Tarek B's user avatar
  • 119
6 votes
2 answers
764 views

Is it a bad practice for a unit test to "trust" the other?

Assume I have the following two functions: function storeObject(object) { // Connect to database // Prepare query // Execute query } function retrieveObjectWith(id) { // Connect to ...
appa yip yip's user avatar
8 votes
5 answers
929 views

Is it bad practice to add "false or" or "true and" to conditionals?

Is it bad practice to add false or ... or true and ... for the sake of promoting code genericness and/or ease of use? As in: SELECT * FROM table WHERE TRUE AND IsEnabled AND SomeField = some_value ...
Nae's user avatar
  • 197
-4 votes
1 answer
42 views

Microservices of different resource type

I am building a system composed of a few micro-services over AWS. I encountered the need of a certain MS to do the same logical work but of a big range of work load. for example, the same logical work ...
Amorphis's user avatar
2 votes
2 answers
604 views

Does it make sense to use meaningless named constants?

For example, does it make sense to refactor the following code: a = a * 2; as: const int INT_TWO = 2; // ... a = a * INT_TWO; My question hinges on the fact that the new constant conveys no ...
Fa773N M0nK's user avatar
2 votes
1 answer
509 views

What is the name of the throw-an-exception on invalid inputs pattern?

In some .NET libraries, there's a pattern of two alternative ways to call a function. int i = x.GetValue(k); /* Might throw. */ if (x.TryGetValue(k, out int i) { /*...*/ } else { /* ... */ } I ...
billpg's user avatar
  • 611
29 votes
9 answers
8k views

In software design, should an application remain agnostic regarding its usage with real world data / mock data?

Let me try to summarize a bit more with a simple example: You're building a large application, a user portal for example, with feeds, news, account management, and a whole range of difference ...
SikoSoft's user avatar
  • 415
0 votes
2 answers
180 views

How to write the following snippet in more cleaner way?

When the caller gives me a call, I need to evaluate n number of criteria which currently I'm doing like if (a & b & c & d & e) Day by day the conditions are growing and it'...
Tom Taylor's user avatar
0 votes
2 answers
181 views

Refactor the method which has the sequence of the similarly looking blocks of code to (or towards) the design pattern(s)

I need some help to understand if the code below could be refactored to something less straightforward, less repetitive and more towards any appropriate pattern. What I feel uncomfortable with in ...
bob-12345's user avatar
  • 103
1 vote
0 answers
74 views

Composing objects: how can I enforce an interface upon each component?

My goal was to be able to create an object which is composed by other objects without having to know beforehand what these objects were, then do checks to see if they actually exist, then add them to ...
Daniel M's user avatar
1 vote
2 answers
733 views

How to avoid magic strings when doing Translations

I have worked in companies that to achieve translations based on the user's localization they use a file to store those translations. However, when they try to access a translation on that file they ...
Ricardo Duran's user avatar
9 votes
2 answers
415 views

Jumpy Code with Descriptive Function Names

I'm currently building out some functionality on a page. When writing JS I've been making a set of smaller functions like FindCarouselLocations(elem), GetImagesFromLibrary(url), and BuildCarousels(...
KGlasier's user avatar
  • 219
-1 votes
1 answer
1k views

Function returning dynamic value [closed]

Imagine you have a chain of functions calls, in which each function is taking the previous function's output as input for the next calculation in the chain. Make an assumption that you are leading ...
Mulder's user avatar
  • 17
2 votes
3 answers
309 views

Design pattern: method that checks consistency of object's internal state

I have got a project in C++. Each of my classes has a method void assert_good() const. The usage of that method is solely for debugging purposes: if the object is an inconsistent/impossible internal ...
shuhalo's user avatar
  • 211
4 votes
2 answers
491 views

How to avoid duplication in a for loop when "initialization step" is identical to "update step"?

I often find a situation where I need to write duplicate codes in a for loop, where the "init step" to identical to the "update step": // duplicate `next()` for (let x = next(); p(x); x = next()) { ...
golopot's user avatar
  • 266
0 votes
0 answers
51 views

Patterns for handling a Multi Responsibility Response string

We have an off shore group that is responsible for a SOAP service. The service has a method that returns a key as a string, when everything goes correctly. When it doesn't the key is an error string. ...
AthomSfere's user avatar
1 vote
1 answer
121 views

How can I prepare my platform to drastically expand for the future?

Preface I'm currently building a very small scale platform I plan on bringing into a trial-production phase here within the next month. As of now, it's just a simple web application. It contains ...
Anilla's user avatar
  • 129
2 votes
0 answers
208 views

Managing application versions using Conan and RPM

I have a shared object that I developed. This shared object is packaged in two forms, a Conan package, and an RPM. It is a Qt project, so it has a .pro file associated with it. Up until now, we ...
J Andrew McCormick's user avatar
1 vote
2 answers
315 views

Should I do a runtime type check inside generic constructors?

Given this generic class and constructor, class A<E extends Number> { A(E number, Comparable<E> comparable) { //... } } it is ensured that a call to the generic ...
user1803551's user avatar
2 votes
1 answer
162 views

Object attributes as special parameter objects in python

I am writing a library that can be used with some GUI and would like to be able to build an interface where user can see and/or change most of the object's parameters, and also write some of these ...
Cos_ma's user avatar
  • 55
0 votes
1 answer
632 views

What is an interim version in Source Control?

I've been working on an open source project recently and have been checking out Core Infrastructure's best practices checklist. One of the items pertaining the "Change Control" checklist is as ...
lucasgcb's user avatar
  • 365
4 votes
7 answers
1k views

How do you know where you stopped in your codes after a 2-week break? [closed]

I just had a more than 2-week long vacation/business trip and I couldn't remember actually what was I working in my coding and where I stopped. Could someone recommend a best practice to solve this?
vyap56's user avatar
  • 175
0 votes
5 answers
1k views

Is it a bad practice to create a global factory?

I am studing the importance of the design pattern and I am not able to understand if could be a bad behavior to create a global static factory class (maybe using singleton?) I put an example hoping ...
micrus_'s user avatar
  • 19
0 votes
0 answers
42 views

Packaging for distribution: include CI config and other files the end user doesn't need in the package?

(Disclaimers: I have checked on Google and this site. I have read this answer, which is the only related one I could find here. Additionally, that answer is from 2017, and I wonder if things have ...
cxw's user avatar
  • 495
-1 votes
1 answer
811 views

Pattern for for REST API who's response depends on behavior of requests to other services

Some one help me with my design paralysis! Assume a microservice (probably going to be implemented in Spring Boot) that has implemented an run of the mill REST API, and after receiving an initial ...
Englishbob's user avatar
1 vote
1 answer
20 views

How to organize work with objects containing different quailties of video

I run into a quite common case of handling Video files with different quality of a video, when the app (on android in this case) should save and use one or another video file depending on a user ...
Gaket's user avatar
  • 111
0 votes
3 answers
5k views

Design pattern for wrapping multiple apis into single api

I have 3 different libraries that provide depth data as well as gesture information. I need to wrap these libraries into a single simpler to use for user api. The apis I am trying to wrap provide a ...
kneelb4darth's user avatar
1 vote
1 answer
325 views

Is there a best practice for storing certificates (e.g. x509), which include private keys, used in unit tests?

In a software library, I wrote, large parts of the code use x509 certificates for various purposes like signing documents digitally. Is there a best practice for storing test certificates used for the ...
Bahaa's user avatar
  • 137
0 votes
1 answer
460 views

use always get and set methods is a bad practique, is call directly an attribute class a bad practique in OOP?

I have a doubt about if there are some recommendations for call directly an attribute in a class I think that in OOP you always should call an attribute by the get method. For example: On set ...
Tlaloc-ES's user avatar
  • 387
0 votes
1 answer
525 views

Methods linking bad/good practices

I have multiple methods calling each other to simplify changing anything in the code and to avoid fixing errors and copy pasting. It looks like this: Is this a bad practice? Does it cause too much ...
Candid Moon _Max_'s user avatar
0 votes
4 answers
147 views

Is there a pattern or best practice for returning dynamically typed data?

I have a method that returns the percentage change of a data in a certain period. After calling that method, i need to know if in the current period the data increased, decreased or is the same when ...
Rafael Dias's user avatar
2 votes
4 answers
487 views

Passing Information to a method using primitives vs and object instance

I have trouble understanding if I should pass an argument to a method as a primitive value or as an already-obtained object. Consider this simple example interface Channel{ String getId(); ...
Logitek Dev's user avatar
8 votes
4 answers
419 views

Should detected vulnerabilities in old commits be remedied?

One of my projects on GitHub has received a vulnerability alert, in this case of moderate severity. The vulnerability has been detected in a dependency of an old version of the code. Current versions ...
s.d's user avatar
  • 243
-1 votes
1 answer
407 views

Node.js / Express.js - Route consisting almost entirely of middleware

Is it a bad design pattern / anti-pattern to create a whole bunch of specific middleware to replace functions in-route. So instead of doing this router.post('/myRoute', (req, res, next) => { ...
SeriousLee's user avatar
-1 votes
1 answer
162 views

What should idempotent script do if resource changed?

I have a script that migrates data in the database. It copies property X to property Y. If I want the script to be idempotent, what should it do on subsequent call if X changed? For example: ...
guy mograbi's user avatar
-1 votes
2 answers
44 views

Logic to create/update values while maintaining their uniqueness (in a multi-threaded environment)

Assume I have a dumb repository which stores numbers (for sake of this example). It is dumb because it may only create new record, update specified record and list all the existing records - no other ...
Dima's user avatar
  • 175
0 votes
2 answers
70 views

Are support arguments passed to functions that help skip certain checks a trap?

Often times, through my framework's importing side of things, I have access to certain data that functions I'm about to use will certainly need themselves. I have "resolvers" that these said ...
coolpasta's user avatar
  • 641
3 votes
3 answers
530 views

Drawing lines with dashes in logs

It can sometimes ease readability to "draw" lines in a logfile. For example: noise noise ----------------------------- Starting Operation ABC blabla blabla ----------------------------- End of ...
Kricket's user avatar
  • 723
2 votes
3 answers
2k views

What are the differences between Threadpool and Object Pool patterns?

I was going through the ThreadPool pattern and it resembles the Object Pool pattern. The only difference that I can think of is that most explanations about the ThreadPool explicitly mentioned the use ...
cervh's user avatar
  • 83

1
2
3 4 5
8