Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [patterns-and-practices]

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

0
votes
2answers
30 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
58 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
153 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
211 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 ...
0
votes
0answers
76 views

Repository pattern: anything besides standard CRUD operations? [duplicate]

I'm using a repository pattern, which exposes CRUD operations on the server-side (swift code): protocol Repository { associatedtype T: Model func getAll() -> Observable<[T]> .......
1
vote
0answers
18 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
633 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
103 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 ...
-1
votes
2answers
38 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 ...
4
votes
2answers
638 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
64 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
75 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
107 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
125 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
80 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
107 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
243 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
119 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
212 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
131 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
64 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:...
2
votes
4answers
227 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
137 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
455 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, ...
0
votes
2answers
155 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
458 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
630 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
200 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
59 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 ...
0
votes
0answers
47 views

Best practices to check permissions in a webapp based on api?

Let's say I build an api server and a angular/react/whatever client webapp. I can authenticate and store auth token, no issue with that. Is there andy best practice on how to handle users ...
3
votes
1answer
107 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
110 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 ...
81
votes
6answers
16k 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
141 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
66 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;} ...
4
votes
2answers
2k 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
66 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, ...
2
votes
3answers
489 views

What design pattern for a sequence of processors over the same list?

Imagine you have a list of Objects - like a list or array of objects representing users - and two processors: one adds/delete/modify some user under certain circumstances the other does the same ...
0
votes
1answer
96 views

Name of different patterns of acting on data in libraries.

I contribute to a couple of open source software, and I've noticed two types of patterns when classes act on data. I am interested in the name of these patterns. The first is something that goes ...
1
vote
0answers
317 views

Create account flow in microservices architecture with different services for account and auth

I'm developing an application based on microservices architecture. Currently my goal is to implement 'Create user' flow. But I'm not sure quite sure what is the right way to do it. My problem is as ...
1
vote
1answer
88 views

Creating a web portal to access multiple databases (security and best practice?)

I am looking to create a website. There will be a portal, from which the user (and thier associated users) can create/access one or more databases. There will be many different databases in the ...
0
votes
1answer
98 views

Should I make constant for values of three choices (trivalent/ternary)?

For two choices there is boolean. In my case, I have positive, negative, and neutral which are three choices and cannot be represented by boolean. I've see there's method Math.signum(x) in Java which ...
3
votes
6answers
847 views

Best approach - convert multiple conditional if -else in a more handy design

I have a class that handles the state of a response, called StockResponse. The code has multiple ifs to handle each state of the stock. Most of the cases has a default behaviour, but some conditions ...
1
vote
2answers
89 views

Bridging application development practices and game development practices

I previously ran into an interesting practice called occlusion culling in game development. I am still researching to gain more understanding of how it works, since this is mostly discussed in game ...
0
votes
1answer
2k views

Best Practice for handling data sync with React Native, MobX and REST?

We're developing an app using React Native and MobX for the state stores, and also using a Web API REST service for the GETs and POSTs. All is going well, so far we're able to use FETCH to get the ...
2
votes
1answer
169 views

Is it a best practice to use a mocking service for testing http requests?

Is it better to unit test using a mock library like 'nock' (nodejs) or to just test the server's http requests directly? Here is an example of my Express server test for testing if my server is up ...
5
votes
2answers
377 views

Designing event-driven architecture for multiple services

I've created about a dozen services for a intranet. Now I've gotten to the point that these services are more coupled to each other than I'm comfortable with, and I've been having problems where once ...
3
votes
3answers
156 views

Best practice to avoid partial branches

I do a lot of coding in python and got a lot of if conditions without an else statement so to say partial branches. E.g.: # if a certain kwarg was passed to a function call if kwargs.get('a_option'):...
1
vote
1answer
550 views

How to control optional dependencies of a header-only library in `CMake`?

I am developing my own header-only library that I want to use as a framework in other software. I am using CMake for setting up demo targets, tests, and so on. However, I am unsure how to deal with ...
3
votes
3answers
642 views

Is it OK to have a many-to-many relationship where one of the tables involved is already a junction table?

When planning our database, we ended up with a setup like this: We have Company, Product and Person. There is a many-to-many relationship between Company and Product, through a junction table ...