Questions tagged [patterns-and-practices]

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

0
votes
0answers
29 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 ...
4
votes
7answers
993 views

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

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?
1
vote
5answers
263 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 ...
0
votes
0answers
31 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 ...
-1
votes
1answer
66 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 ...
1
vote
1answer
17 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 ...
0
votes
2answers
134 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 ...
-1
votes
1answer
78 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 puprposes like signing documents digitally. Is there a best practice for storing test certificates used for ...
1
vote
1answer
144 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 ...
0
votes
1answer
153 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 ...
0
votes
4answers
130 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 ...
1
vote
4answers
99 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(); ...
8
votes
4answers
385 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 ...
-1
votes
1answer
193 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) => { ...
-1
votes
1answer
90 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: ...
-1
votes
2answers
42 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 ...
0
votes
2answers
62 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 ...
3
votes
3answers
156 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 ...
2
votes
3answers
461 views

What are the differences between Threadpool and Object Pool patterns?

I was going through the ThreadPool pattern and it resembled the Object Pool pattern. The only difference that I can think of is that most explanation about the ThreadPool explicitly mentioned the use ...
1
vote
0answers
27 views

Doing operation on entity or dto

I use jpa and spring. I have facade where I convert habitually entity to dto. In the service layer, I call method to repository to get entity. For display, I need to do some operation on data. Is it ...
7
votes
4answers
651 views

Should I test a method that calls a method that is already tested?

I have a method that does something like this public void addFunds(Account account, int price) { int credits = account.getCredits() account.setCredits(credits + price) saveOrUpdate(account) }...
3
votes
1answer
104 views

Is good or bad practice to share reporting modules between systems/apps?

At my new work, a few people want to share modules between systems/apps, and I'm a bit skeptical about it. Context: we have a lot of little apps living in different servers, some of them are ...
0
votes
2answers
40 views

Web Services with Android and iOS apps

I have a website which uses REST Api for communication. All data retrieval and save happen through Rest Api calls(polyglot environment). Now I am planning to create an Android and iOS app . I have ...
5
votes
2answers
9k views

Best practice for REST API call with many parameters

I have a REST API with GETs operations which receive a (long) list of parameters (8 parameters, for example). The aim of this operation is to search and filter elements. Which is the best practice to ...
2
votes
0answers
71 views

Performance: Creating duplicate file

I have a Web server (Local) and File server(Remote). I need to create a duplicate of an xml file in the same location with different file name in the File server. The size of the file is random, but ...
1
vote
0answers
116 views

What Design Pattern to use to render PDF pages for a PDF Proposal?

I want to create a set of patterns to use for rendering a PDF Proposal (a set of PDF pages). I have made a good start, but not clear on how to proceed when more complexity is involved. I am using ...
-3
votes
1answer
117 views

Is it a good practice to always apply CSS styles to the innermost nested element? [closed]

Let's say you want to center the text here: <div class="wrapper"> <div class="content"> <p class="body"> GUCCI GANG, GUCCI GANG, GUCCI GANG, GUCCI GANG, ...
0
votes
2answers
128 views

Pattern name for a class inheriting of a generic based on itself

I'm wondering if there is a name for the pattern of defining a generic class with one type argument where the type inherits the defining class. For example public class A<T> where T : A<T&...
0
votes
1answer
161 views

Is it bad practice to hard-code values in ASP.NET's web.config file?

I work for a company that is building a web application with ASP.NET & MVC, which was last worked on a few months ago. I am part of the team working on the project and have encountered values (...
2
votes
1answer
111 views

Traversing over two similar object structures using a pattern

Let's say I have an Object Structure like this that I import data into from a source: Reporting: Body: ReportingEntity: DocSpec Reports[]: ConstEntities[] DocSpec ...
1
vote
4answers
267 views

What should be the last entry in a switch/case statement?

When writing a switch statement that only ever has to deal with a known set of values (imagine an implicit enumeration), I find myself wondering what should be the last entry in the construct. I'm ...
4
votes
2answers
292 views

Handling disposables with dependency injection

I'm struggling to implement disposable objects via dependency injection, as the dependencies are injected in the constructor (and live as long as their containing object does), whereas I want the ...
2
votes
2answers
218 views

Should I fix known bad domains in user emails?

Checking my Sendgrid account I've noticed many drops due to "Known bad domain". Those bad domains often seem to have been caused due to user mistake. ***@gmal.com ***@gmail.com.br ***@hotmal.com I ...
0
votes
1answer
268 views

Enum as part of domain - enum + extension or consolidate into one class?

I have a program where the domain is focused around programs. As part of the domain, I have a 'ProgramType', which is an enum formed mostly via a string from the database but also via a bit of logic. ...
1
vote
1answer
170 views

How to design service layer when working with model objects and relationships

I have a simple relationship where top-level items (Recipe) have a one-to-many relationship to children (Ingredient) and each item has a unique identifier (ID). For simple CRUD operations the flow is:...
3
votes
4answers
404 views

Inheritance best practice?

I'm fairly new to object oriented programming and have a question I've stumbled upon regarding inheritance best practice. I'm building a system for weapons in a game. I have a base class called ...
0
votes
1answer
142 views

How to write clean code accessing nested members on higher abstraction levels in c#

What are best practices for cleaner code style when accessing nested members on higher abstraction levels. class A{ B b; void Do(){b.c.d.e.f.g.value;} } class B{public C c;} class C{public D d;} ...
-4
votes
5answers
596 views

Why do programmers like to stick to “Thou shalt” / “Thou shalt not” rules that define whether a code is of good or bad quality? [closed]

I'm not sure how to correctly describe my problem... Ever since I started learning how to program, I recognized that many more experienced programmers have very strict (and, in the POV of a beginner, ...
1
vote
2answers
304 views

DDD: Is there a place for “find or create” in the business logic

Some user actions quite naturally lead to find-or-create situations. For example, user logs into a system by alternative method and find-or-create is called give email. Or, another example, User is ...
0
votes
1answer
893 views

Best design pattern for Notification System => How to handle multiple languages and items

As always I came here to ask for some light in a design issue I am facing. I have a system that issues some notifications : PackageReceivedNotification PackageSentNotification ...
7
votes
5answers
814 views

With TDD, tests obviously fail first.But is that really true?

I have been taught that with TDD, the tests "naturally fail first but it is a good habit to run them anyway to see the red light". Well, but I am quite sure a unit test written first for a new feature ...
2
votes
2answers
207 views

Reading huge (up to 32 GB) file in multithreading env?

Goal: 1) huge file read in chunks each 1 MB long, 2) each one gets compressed and written to an another output file. Note: I am limited to .Net 3.5 only. Is there a known pattern how to parallelize ...
1
vote
0answers
96 views

When “cloning” an object in javascript should the clone behave as the original?

I'm using the webgl framework three.js. Most of the classes can be "cloned" via a .clone() method. Wikipedia seems to be very strict when it defines "cloning". In computer science, cloning ...
3
votes
1answer
117 views

What is best practice for handling mapping arbitrary depth in arrays?

I have a set of data: id | name | parentid ------------------------ 1 | parent | 0 2 | child | 1 3 | child | 1 4 | parent | 0 5 | child | 4 6 | subchild | 5 7 | child | 4 ...
4
votes
1answer
124 views

Design pattern to instantiate implementations depending on properties

I have an interface: public interface MyInterface{} And two implementations: public class Imp1 implements MyInterface {} public class Imp2 implements MyInterface {} My program is a CLI. I want to ...
84
votes
6answers
17k views

Is it bad practice to enforce an execution order for unit tests?

I am writing tests for a project that consists of multiple submodules. Each test case that I have written runs independent of each other and I clear all data between tests. Even though the tests run ...
3
votes
1answer
142 views

What is the standard method of handling errors in a NodeJS web app?

I am currently working on a web application as a learning project, which has a NodeJS backend and uses a MongoDB database; however, I believe my question is not specific to the technologies I am using....
1
vote
2answers
69 views

Mapping entities to VMs and back - should we use operator overloading or constructor + a convert method?

I got the following entity and VM: public class Student { public int ID {get;set;} public string FirstName {get;set;} ... } public class StudentVM { public int ID {get;set;} ...
7
votes
2answers
5k views

Best practice for exception handling in Java threads

long-time reader, first-time asker here. I have a service which writes data to a database in batches. It contains a buffer which is being watched by a separate thread. Whenever the buffer reaches a ...
0
votes
2answers
67 views

Restore backup with recent changes (not included in backup)

For a web application I was asked to design a backup strategy. At the moment there are hourly full backups (database and files). In light of the GDPR, and because it's just the way it should work, ...