Questions tagged [design-patterns]

A design pattern is a general reusable solution to a commonly occurring problem in software design.

Filter by
Sorted by
Tagged with
0
votes
1answer
101 views

how to use Builder pattern combined with protected access modifier?

I'm reading a book in Design Patterns, and below is some code example used by the author. The author tries to build a html builder as (code in C#): public class HtmlElement { public string Name, ...
2
votes
1answer
152 views

Is this the right way to handle errors using the fetch api?

I am using the fetch api in my handleSubmit function in a React component to post data like this: handleSubmit(event) { event.preventDefault(); var error = false; var { username, password } = this....
1
vote
1answer
64 views

mongodb queries architecture - resolving lots of nested referenced objects

I have an angular 8 application, with a Python + MongoDB API on the backend. At present, I have 4 collections, namely: Users, Tasks, Companies and Groups. All of these resource types are retrievable ...
1
vote
1answer
208 views

Is it acceptable to invoke business logic inside the repository layer?

I'm learning DDD and I'm wondering if it's ok to invoke domain model logic from inside the repository layer? I don't mean that the business logic exists as part of the repository, merely that the ...
0
votes
0answers
44 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. ...
0
votes
1answer
54 views

How to access parent relationship in repository pattern

I have two models Permission and Role, now in roles/create, I need to show all the available permissions to allow admin to select the permission and create a role, now should I import both ...
1
vote
1answer
91 views

DDD - Hardcoded Ids in Domain Model [closed]

I have a Business Layer, where I have put all the Entities of the Domain Model. Also there are Domain Services, where I put Domain Logic related to n Entities. One entity is : public class ...
-2
votes
2answers
329 views

Is using a pattern on a completely wrong way a terrible mistake [closed]

This is maybe a strange question, but I just trying to understand my colleague. I know what is DTO, and what should be on it, but not that long time ago I found the whole micro-service written on the ...
0
votes
1answer
62 views

When to fetch/send data in an Android application

I am currently creating an Android application and I have the following questions: We have a server which provides data for the app in form of a REST-JSON-API. The App is following the MVVM ...
0
votes
2answers
66 views

Architecture for multi layered role system

I want to make three layers of application all served through Rest API. For a user case we can say it's school management system where there could be multiple schools where the teachers are ...
0
votes
1answer
59 views

What DB design pattern it is: main entity has field with actual value and details are in separate table? [duplicate]

I have PERSONS entity and I should add ASSIGNED_LEVEL (INT) field to it and keep the history who assigned the level, when assignment was done and what documents were used in the assignment. My ...
0
votes
1answer
56 views

How process dynamic rules for product configuration?

I need to find a software architecture to support object configuration and validation in a dynamic environment. Lets say I want to configure a bike where I have many physical components available to ...
0
votes
2answers
236 views

Domain Driven Design too many structs

I'm trying to apply DDD to a Golang service and sometimes I find that I have too many structs. For example, I need to satisfy the requirements (for simplicity, I reduce the number of required fields):...
5
votes
4answers
397 views

How to keep class/file name short but still descriptive?

I've been working on a C# class library with the mindset that we will have new developers to work on it later. While I tried to keep the class/file name as descriptive as possible, the length is ...
0
votes
0answers
55 views

What is the correct way of setting and then differentiating between paid and free user in Firebase / Firestore?

I am developing a mobile application that will have both free and paid versions. The way I see how I could differentiate between what is a paid and free user is to set a property isPaid on their ...
1
vote
2answers
113 views

Chain of responsibility or simple dependency injection for Querying API

I am working on refactoring a project code that is wired up in a tangled way. It was started with decent dependency injection and over time with all custom requirements it looks it got tangled up. ...
2
votes
1answer
179 views

C++ How to build a common interface with the possibility to call functions specific to only one class

I am building a common interface for several different backends that are shared libs loaded at runtime dependend on the used platform. It looks basically like the code below. My problem is, that while ...
6
votes
6answers
547 views

Should error codes in JSON be integers or strings?

I'm designing a backend webservice, and when an error occurs I'm returning it as a JSON to the frontend. This JSON contains an error code, which the frontend maps to an localized string and shows that ...
1
vote
1answer
85 views

Structuring a pipe for function composition when an intermediate result is needed by later functions

I have a set of pure functions that can be composed almost trivially in a pipe as initialValue -> [f] -> [g] -> [h] -> ... -> [m] -> [n] -> [o] -> outputValue The problem I ...
2
votes
2answers
123 views

Is inline still necessary when using the Named Parameter Idiom?

The Named Parameter Idiom as described here mentions that there will be a performance impact when not using inline. Since each member function in the chain returns a reference, there is no ...
0
votes
2answers
252 views

C++ tactics / data structures / design patterns to avoid or postpone unnecessary object creation?

A couple of months ago I wrote a C++ program for computational mathematics that was supposed to compete with a highly optimized C code. After a while I did manage to get it fast enough to beat the C ...
3
votes
2answers
143 views

Do I use Repository or Service Object to Perform Logging?

I'm working in Java Spring, and I have typical service and repository layers. The repository grabs a JSON; passes it along to the service; service maps the repository response to a DTO. I also need ...
6
votes
3answers
875 views

Write a method with same logic but deals with different objects

Assume I have the following method that does the same logic but deals with different objects (It's more a pseudocode): private <E> List<E> updateOrInsert(List<E> list) { if ...
10
votes
2answers
675 views

How does functional programming handle the situation where the same object is referenced from multiple places?

I am reading and hearing that people (also on this site) routinely praise the functional programming paradigm, emphasising how good it is to have everything immutable. Notably, people propose this ...
3
votes
2answers
272 views

Does my class violate the Single Responsibility Principle in SOLID?

I want to ask: Whether the Role class violates Single Responsibility Principle in SOLID ? I think deleteAccount() is not belong to Role class but Role class is way to extend code in the future ...
2
votes
3answers
280 views

Wrapper Class Should be made static?

I am planning on creating a wrapper class in c# which will call cryptographic functions provided by .Net Framework, just to make sure I am clear, I am not writing any cryptographic algorithm, just ...
1
vote
1answer
174 views

Best practices: Save or return intermediate results?

Assuming IO is not an issue, is saving intermediate results considered a best practice? What are the pros and cons, and situations that warrant doing so or not? Say I have two components along a long ...
2
votes
2answers
346 views

Is observer pattern abandoned by the industry now (2019)? [closed]

While working on a refactoring task of a legacy app, I came across a scenario where a series of cause->effect type events are happening and currently everything is being handled inline. To give you ...
1
vote
1answer
49 views

How to handle or design review system with pagination?

In typical online review system if any user give review on specific post or others thing, then when that user view that post his review show first. The perfect example of this is Google Play Store. If ...
0
votes
1answer
107 views

Avoiding downcasting in PHP

This is a theoretical problem that bothers me. Let's say we have following, simplified structure: interface ParagraphInterface {} interface ParagraphGroupInterface { public function ...
3
votes
3answers
366 views

Are Result objects the cleaner way to handle failure, than exceptions? [duplicate]

I was watching the following video by Vladimir Khorikov, which recommends to "Refactoring Away from Exceptions" pluralsight.com - Applying Functional Principles in C# - Refactoring Away from ...
0
votes
1answer
31 views

What form of single instance class for a cache under Android

The app is to communicate with a bluetooth device with assorted data (config, measurements, service logs, status telemetry) - and it should cache obtained data so the user flipping between activities ...
3
votes
1answer
126 views

C++ pattern for compile-time configurable class functionality

Due to resource limitations (embedded), I want to make some functionality that a class provides optional. The decision to include this optional functionality should be made at compile time. For ...
0
votes
5answers
209 views

What if there is specific logic for one particular value of an enumeration class?

Background: I have seem some argument for using enumeration classes instead of enum in C#, in particular, this section from a book available at MSDN. On the references there is this "Enums are Evil" ...
0
votes
3answers
104 views

DDD and Infrastructure micro-Services - how should the interface be designed?

We've extracted our email sending into an EmailService - this is a microservice that provides resiliency and abstracts the email logic into an Infrastructure service. The question is how the ...
-2
votes
1answer
387 views

How to create a league scheduling algorithm?

Our requirement was to create an auto fixture generation tool that creates fixtures for a league with any number of teams, and where they have a fair distribution of home and away games so that: ...
0
votes
1answer
90 views

Granularity of the Single Responsibility Principle [duplicate]

This is a related question and the OP appeared to go with extreme levels of granularity. The answers gave a good overview but I gather it's still somewhat down to personal interpretations/situations ...
3
votes
3answers
309 views

Which is a better method name? GetById(int id) or Get(int id) [closed]

Has there ever been a consensus on which convention is "better": User.GetById(int id); or User.Get(int id); i.e., is User.Get(int id); not descriptive enough? Or does is the parameter implication ...
1
vote
3answers
203 views

Use just one parameter for all dependencies instead of many?

I understand that having 3 or more parameters as dependency is a sign that the class may be doing too many things, however there are cases that the class really needs more than 3. My question is, is ...
6
votes
8answers
771 views

How to apply OOP to real world examples without putting all logic in Manager classes?

I'm lately trying to implement a specific problem using an object-oriented approach. I get the main principles and its advantages, but I fail to apply it to a real world problem. Most examples one ...
1
vote
2answers
188 views

JHipster generated endpoints adds header messages

I'm adding new functionality to an existing application it was done using JHipster. I've notice that some endpoints follow this pattern: return ResponseUtil.wrapOrNotFound(updatedUser, ...
0
votes
3answers
362 views

Code Design: Repeatedly doing the same Boolean check with Stream Writer

I have several areas in a program where I am doing the following check on the same two booleans, but each spot has different text being written to a file via Stream Writer based on the value of the ...
2
votes
1answer
130 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
123 views

c# Fluent Builder and invalid object state

I have a question about Fluent Interface Builder. I have a simple object like this: public class Person { public string Name { get; set; } public string Surname { get; set; } public int ...
0
votes
2answers
175 views

Best design for a AMQP work queue

I have a system where a user uploads a file to import some users but it's necessary to do some validations and this take some time. I would like to create a work queue with RabbitMQ and the user will ...
0
votes
1answer
52 views

Design pattern that can be used for checking and handling a change in version number for incoming JSON message into data stream?

I have a Spark Streaming Job which processes messages coming from Kafka. My incoming json that I process sort of looks like {"sv" : 1.0, "field1" : "some data"} The only thing I do is put these in ...
0
votes
1answer
186 views

Dependency injection: Is there a better way than new A(new B(new C ()))? [closed]

I'm just learning about dependency injection. Unfortunately, I don't have the luxury and time to learn a DI framework right now so I am attempting to do DI through some simple means. Say I have an ...
-2
votes
2answers
71 views

How do I model all the different states of a widget for testing?

Say I am a QA person so I have no control over the complexity of the code in the following example. I have a datatable widget with many different filtering and searching options. All the columns on ...
3
votes
1answer
198 views

How to make updates to data and return list of updates without breaking Command query separation or DRY?

I have a use case to make updates to a slightly complex JSON object and then return the list of changes made (not the updated data). The process of finding the list of changes is extremely similar to ...
2
votes
1answer
100 views

What to do when you want to apply some common functionality to some specific methods?

I am trying to figure out a design pattern to use (if any exists) to a situation where I would be re-doing some functionality across a bunch of classes. Below is a (simplified) overview of the problem ...

1
3 4
5
6 7
76