Questions tagged [patterns-and-practices]
Design patterns (repeatable solutions to commonly occurring problems) and best practices in software engineering
366
questions
0
votes
1
answer
26
views
Multiple objects using the same connection for communication, filter messages "above" or inside the objects?
I have a single connection being used by multiple devices, and I'd like to filter the messages so that each device only reacts to messages intended for it. This can be done with an unique ID field in ...
2
votes
3
answers
168
views
Class design using Open and Close Methods
As the title says, Im thinking if it's a good practise to have classes that have Open and Close methods in the sense that they can be reused without a new instance being created again.
Also, if I want ...
0
votes
1
answer
75
views
Logging, with optional foreign key cross reference
I am wanting to enhance a system to execute various background tasks (primarily data importation). In order to provide data for support, analysis and job status generally, I had been thinking of ...
0
votes
0
answers
45
views
Pattern for Nuget Package (Abstractions, DepedencyInjections, etc.)
I've been interested in following what other successful libraries are doing with their nuget packages. Unfortunately, I can't seem to find any materials to read online and I don't even know what to ...
1
vote
4
answers
710
views
I wrote a class with "init" method. Should I call it from other class methods? Or leave it to the object user? (Code Design)
I have a java class with an init method. It's different from the constructor. The constructor just initializes the variables/fields. The init method connects to a database and performs some ...
-1
votes
1
answer
165
views
Why have a path argument when there is cwd
When writing a program that uses a working directory, e.g., PostgreSQL data directory or download target for wget, is there an advantage of having a CLI argument (or an environment variable) for such ...
1
vote
2
answers
165
views
Refactor chunks of code where variables from one chunk are used in others
What is a good pattern to refactor a chunk of code where you can identify smaller chunks, but the results of these smaller chunks are used in other chunks?
An example should make things more clear. ...
-1
votes
1
answer
94
views
How can I prevent an object from being re-sanitized everytime it is passed as input to a function?
Suppose that I have a class named CharStream
Additionally, there are a large number of functions which convert their function input into a CharStream
def funky_the_function(_input):
input = ...
1
vote
1
answer
112
views
Is it an acceptable pattern to put derived classes inside an abstract base class in Java?
Suppose I have some Java code such as the following (in this case, the use of the name "interaction" is referring to interacting with an object in a video game):
public abstract class ...
1
vote
0
answers
109
views
Reuse and sharing with primitives
I am having trouble naming and thus searching for the right keywords for a pattern I am seeing in my web applications and their associated difficulties. Here are some examples of the pattern I mean:
...
1
vote
1
answer
983
views
DDD: Can application services throw domain errors?
I'm new to DDD and I trying to create an API using DDD concepts for study purposes. Today, I faced a scenario where I've to create an Application Service to expose a functionality to be cosumed from ...
1
vote
3
answers
109
views
Separating network logic from business logic
I am creating a simple P2P file sharing system, where one peer can send some Objects (e.g., String, custom objects, etc...) to another peer.
The peer, that receives the Object, can then manipulate it, ...
0
votes
2
answers
171
views
Why session should be a param when you write a query function?
I read a lot of examples where I read code like this:
def get_user_by_id(session, id)
...
and the function that calls that function needs to create or get the DB session a pass to the function.
the ...
-1
votes
2
answers
136
views
Appropriate design pattern for coupled Objects
I code an Object-Oriented simulation where you can have a Unit move on a Terrain. The cost of such move depends both on both Unit capabilities and Terrain features: a boat can move on water, a plane ...
2
votes
3
answers
487
views
Is a method named createOrUpdate() violating the single responsibility principle? Should I split into create() and update()?
I work developing software, and very often I find inconsistency in the company's code. The thing is, there is a method named createOrUpdate(), and this method basically does what its name says, ...
-1
votes
3
answers
498
views
Would Injecting dependencies in C# as default parameters be a bad practice?
Given the (old) debate over whether Singletons are overused/abused/are worth it - would it be a bad idea to inject the dependencies as default parameters? In this way, we could get rid of defining ...
0
votes
2
answers
423
views
Best pattern/practice to execute a multi-step code generation process
I am working on a project that generates an API with the possibility of doing CRUD operations based on a high-level description of the resources that the user would like to have in an application. In ...
1
vote
2
answers
1k
views
Difference between Strategy pattern and Repository pattern
I found the following definition of Repository Pattern:
Repositories are classes or components that encapsulate the logic required to access data sources. They centralize common data access ...
1
vote
1
answer
144
views
Free standing functions usable for Base pointers
I read multiple times that when a member function only uses API of class it is member of, then it should be made free standing and put in to same namespace, for example, bad practice:
namespace A
{
...
0
votes
3
answers
102
views
Should we test private data (static objects in this case) to make sure it maintains its structure?
I had a discussion at work about whether to unit test a private static object we're using as data for a public component.
const data = {
45: { name: 'John' },
2: { name: 'Patricia' },
27: { name: '...
-1
votes
1
answer
102
views
How to reconcile CD with major architectural changes?
(This question is inspired by the SO blog entry Fulfilling the promise of CI/CD and this old question of mine: Why is it wrong to comment out code and then gradually remove it to keep track of what I'...
0
votes
1
answer
210
views
Should I use SCSS mixins as shortcuts for default CSS syntax?
This question is mainly about readability and understanding of the code. Im am also in the process of creating a SCSS framework like Compass and Bourbon.
I struggle to write SCSS because I like to see ...
23
votes
5
answers
7k
views
Where did usage of OS signals go?
From what books I read on linux system programming, it seems like signals were the primary way to communicate events between processes. They were the gateway into many interesting functionalities, ...
0
votes
1
answer
405
views
Source of "... against the interface, not the implementation"
For a paper I am writing, I need to find the origin of the following two phrases:
Code against the interface, not the implementation
and
Test the interface, not the implementation
(Note: the ...
13
votes
2
answers
4k
views
Code duplication vs. abstraction
I've inherited some research code where there's already a fair amount of code duplication: on several occasions, the original author duplicated a file and changed minor things to calculate a variation ...
2
votes
2
answers
277
views
Understanding passwordless sign up for mobile apps
How does phone number based authentication work, and what are its best practices?
I've noticed there are apps with streamlined sign-up/log-in processes where only a phone number is required, simply ...
2
votes
4
answers
1k
views
Confused about inheritance and correct usage. Should I avoid using members in base class?
I am using C++ , but as far as I understand most OO principles are cross language.
In most of the articles that I have read and liked about inheritance the advice are about :
not to use it for the ...
0
votes
1
answer
373
views
Is it bad practice to run different versions of code in different environments? (i.e. test, prod)
As an example, let's say you have the following pseudocode:
if test environment: # meaning you don't have the typical service account prod perms
sudo as service account + do operation
else: # in ...
1
vote
4
answers
119
views
Should I public method and test it instead of testing a caller
I have a method called GetValueA() and GetValueB() which return string that in formatted
public string GetValueA(){
string a = service1.GetA();
return Format(a);
}
public string ...
6
votes
1
answer
512
views
Methods with "With" prefix?
I started working on a project and I saw some methods with this With prefix and I'm wondering if this refers to a known pattern.
Does anyone know of this naming pattern?
0
votes
2
answers
107
views
Calling general-purpose methods from the code that clearly needs only specific behavior
Here are a couple of examples in Python:
clearly_even = 2 * get_integer()
print(solve_for_any_integer(clearly_even))
def solve_for_any_integer(x):
while x % 2 == 1:
x = make_even_from_odd(x)
...
0
votes
3
answers
117
views
Strategy & Architectural Decision: Customer data migration between two companies
Asked this originally here, and didn't receive any answer so far, hence posting here too.
Let's say company A acquired company B in a certain region. This means, A and B were competitors in that ...
1
vote
4
answers
218
views
When should a method depend on a data source and NOT have it declared as a parameter?
I was assigned a code review to one of my colleagues.
I posed the following, which I wanted to share here in order to hear whether I am right or wrong.
Consider the following code snippet:
public void ...
6
votes
4
answers
655
views
Is there a standard name (or examples) for the "sandwich" pattern?
I've noticed a certain idea recur in different contexts, but before I start calling it "the sandwich pattern", it would be useful to know (in the spirit of other "Is there a name for ...
0
votes
3
answers
200
views
Sysadmin password storing
I'm quite unexperienced in the sysadmin area. Now I'm facing the responsability of managing two (remote) servers. I'm working in an informal organization.
So I have passwords for the OS's users, ...
2
votes
2
answers
127
views
What pattern for translation is better, naming the key by screen/context or by text?
I'm in a dilema where I'm translation a full mobile app where the translations are going to be a key value pair but I'm not sure how to name the key.
Should I name the keys describing what the text is,...
0
votes
0
answers
72
views
Can someone suggest what pattern I used mistakenly and is it correct in this situation. Any alternative?
Client_1 uses --> IService_1 and thus Service1_impl
public interface IService_1
{
void DoTask_1();
}
public class Service1_impl : IService_1
{
private readonly IDepService_1_v1 ...
1
vote
1
answer
124
views
Who should log output, the ThingDoer or the code which calls ThingDoer.DoThing()? [duplicate]
Here's a common question I ask myself:
If I have a ThingDoer class and it has a method DoThing(), and I want to log a message stating "Doing a thing", should I put this logging code in the ...
4
votes
2
answers
204
views
How should my application treat database collisions that are handled safely?
My applications uses error reporting to track exceptions.
My application uses SQL transactions to make sure that operations are completed completely or not at all.
My application is multi-threaded.
...
1
vote
1
answer
82
views
Deisgn Pattern: How to map UI requests to Controllers to Services?
I'm learning about writing WebApi design patterns.
I am trying to create a simple CRUD web app with ReactJS UI and C# .NET CORE webapi with sql backend.
Articles show that specific Repositories are a ...
4
votes
2
answers
111
views
Separation of data retrieval and processing in loops?
Often I need to get some data and process it in some way. For example getting a list of customers from an API and assemble some summary data on them. As an example, getting :
api_result = api.request(...
2
votes
1
answer
508
views
Reusing aggregate root key across bounded contexts?
As the question states, is this bad practice?
I have a User aggregate root in the bounded context of Identity for authenticating the user. In this bounded contexts I have fields for the User related ...
0
votes
2
answers
79
views
Logic in data provider vs test body
Lets say we have a class Cat:
class Cat{
public eat(String food){
if (food.contains("cat")){
burp();
}
}
private burp(){
System.out.println(&...
1
vote
1
answer
473
views
Communication mechanism among windows or pages WPF
I work with C# and WPF and not using MVVM approach. One of the important part of applications is communication among Windows Pages and UserControls. In MVVM they do it behind the scenes and let you ...
0
votes
0
answers
55
views
What best practices/principles could help me improve my routine call placement?
I'm trying to change my module's outline since I feel I'm blocking some reuse possibilities, but I don't know how to justify it under the lens of good practices/design principles. Keep in mind this is ...
39
votes
8
answers
9k
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 ...
1
vote
4
answers
768
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 = ...
5
votes
2
answers
855
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 &...
-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 ...
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. ...