Questions tagged [patterns-and-practices]
Design patterns (repeatable solutions to commonly occurring problems) and best practices in software engineering
372
questions
0
votes
0
answers
75
views
Deciding between two design alternatives for displaying series of screens in mobile applications?
I am developing a mobile application, and one of the features is a "story" that is essentially a series of screens. The screens can be of three main templates:
A "video" template ...
-1
votes
2
answers
122
views
How to handle complex logic, avoiding recalculation for performance reasons?
let's say we're building an Ecommerce Marketplace.
We have Sellers and each Seller has Products.
We want to display a list of available Products across all Sellers to Buyers.
But, we only need to ...
0
votes
4
answers
188
views
Should a null block be used for semantic purposes?
I was writing a procedure that is only applicable in a particular case, but it didn't feel right to enforce it by contract or raising exceptions, because there's no problem with calling it in other ...
1
vote
2
answers
146
views
how best to take a vertical slice of something already trivial?
Lets say I have a project which is something relatively simple like a copy checker for legal text files stored in git, that multiple people contribute to via pull requests that must be reviewed before ...
-1
votes
1
answer
88
views
Is there any benefit/viability to sharing models across API versions that have differing schemas
I have been asked to get involved with a Team that is currently having delivery issues for various reasons. During my review I came across an acceptance criteria on a user story;
If you call v1 of ...
0
votes
1
answer
113
views
Storing Data For Consumption in Python
I have a program which needs some constant data, in JSON-like format. However, this data only needs to be consumed by my Python program, and by making it Python code, I can include types like datetime....
0
votes
1
answer
34
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
175
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
112
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
196
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
2k
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
200
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
177
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
102
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
173
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
111
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:
...
2
votes
1
answer
2k
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
163
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
191
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
137
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 ...
3
votes
3
answers
2k
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
743
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
728
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
2k
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
151
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
121
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
109
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
276
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
610
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 ...
15
votes
2
answers
5k
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
292
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
2k
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 ...
1
vote
1
answer
695
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
122
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
776
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
111
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
119
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
221
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
759
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
211
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
139
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
75
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
153
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
250
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
142
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
135
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
566
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
99
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
661
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 ...