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
0
votes
2answers
111 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'...
3
votes
2answers
157 views

When to use third-person verb? (PlayOnAwake or PlaysOnAwake)

First a couple of examples: var val = obj.GetValue(); var can = obj.CanPlay; var has = obj.HasValue; var val = obj.RequiresConstantRepaint(); // From Unity var val = obj.PlayOnAwake; // From Unity ...
-4
votes
0answers
79 views

Return result at the same line, without defining intermediate variable, pattern or anti-pattern? [duplicate]

I haven't found discussion on this topic. If there's an old discussion here where this issue has been discussed please link it, and I'll close my question. Two examples: function random(number) { ...
0
votes
2answers
102 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 ...
1
vote
0answers
62 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 ...
1
vote
2answers
222 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 ...
9
votes
2answers
380 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(...
-1
votes
1answer
52 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 ...
0
votes
0answers
17 views

Keeping entities in sync between SalesForce and operational application

We’re in the process of rolling out an application (let’s call it X) that has a database with users and organisations. X has an admin interface in which our admins can create, update and delete these ...
2
votes
3answers
90 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 ...
4
votes
2answers
353 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()) { ...
0
votes
0answers
43 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. ...
1
vote
1answer
112 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 ...
2
votes
0answers
60 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 ...
0
votes
0answers
48 views

Internal design of Android app

I have an Android app which stores data in a file system. This file system synchronizes with a server when there is an internet connection available (but is designed to work without a network ...
1
vote
2answers
124 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 ...
2
votes
1answer
128 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 ...
0
votes
1answer
166 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
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?
1
vote
5answers
308 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
32 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
96 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
18 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
3answers
378 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
106 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
151 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
184 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
133 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
132 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
390 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
299 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
117 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
64 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
166 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
753 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
33 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
701 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
108 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
45 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 ...
11
votes
2answers
24k 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 ...
3
votes
0answers
76 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 ...
2
votes
0answers
141 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
121 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
134 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
283 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
119 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
376 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
521 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
228 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 ...

1 2 3 4 5 7