Questions tagged [design-patterns]
A design pattern is a general reusable solution to a commonly occurring problem in software design.
4,519 questions
0
votes
0
answers
127
views
Is having many thin factories an antipattern?
I need to perform the following task: for a user [email protected], store a blob of data into their dedicated data store.
DataStoreService is what actually stores the blob of data in the user's store, ...
4
votes
4
answers
1k
views
When should tuples be used as an argument instead of an array?
I hope this isn't too off-topic/opinion-based, I'm new here.
I want to pass three elements of the same type into a function. The three elements are unique cards of a deck of cards, so they're not ...
1
vote
0
answers
100
views
Mimic public/private data members in C with hidden static arrays
Context
I'm designing the software architecture of a safety critical software written in C, under DO-178C (DAL A) and with a Code Standard based on MISRA-C 2012, but no fully compliant.
It is the ...
3
votes
0
answers
349
views
API Gateway Design Pattern - Backends for Frontends
I am contemplating the use of the design pattern API Gateway, specifically the Backends for Frontends derivative.
We have a number of 3rd party software packages that expose an API. Over the course of ...
1
vote
1
answer
119
views
In the state pattern, what happens when the action doesn't depend only on the state?
I have some doubts about the state pattern, but I think it is better to ask one question at a time, so it is easier to focus on the answer.
The state pattern establishes which actions can be performed ...
1
vote
4
answers
409
views
Is there any intent behind SRP other than SoC
Edit based on responses so far
I am starting with an edit so as to save future contributors from going down the same path others have.
I am only interested in contributions that stick to the exact ...
3
votes
2
answers
3k
views
Standard error codes vs custom error codes in C
I am working on improving the code quality and portability of my C library, specifically a ring buffer implementation, that will be used in larger applications. I have encountered a dilemma regarding ...
-1
votes
2
answers
143
views
Flexible design approach vs maintainabilty/verifiability
Currently, I have to define a general design approach concerning the future extensibility of a software written in C#. The software is built in modular design: A main part doing the general handling, ...
0
votes
2
answers
143
views
Services: Which structure is a better idea?
I'm designing my service layer for a GraphQL API and there are many situations in which I can't decide if code relating to a table should belong in it's own class, or the class that 'owns' the data. ...
0
votes
1
answer
131
views
Multi dimensional lookups
I am looking to see if there is a general design pattern or strategy to handle a use case I see often in our codebases. My best attempt to generalize this use case is "Map permutations of n ...
0
votes
2
answers
386
views
Usage of overrides in the State design pattern
Imagine a situation where out of 5 state implementation classes the implementation of a method only differs on 2 of them (i.e. 3/5 share the same implementation for a particular method).
This ...
0
votes
2
answers
531
views
What is the difference between C++ Composite and Chain of Responsibility patterns?
A Composite delegates calculations of unknown depth to a virtual method.
A Chain of Responsibility passes events to an arbitrary deep line of handlers.
Sounds the same to me. What am I missing?
0
votes
4
answers
360
views
Object matching using generic method? [closed]
I have a piece of code where two objects (incoming request object and a profile object) are to be checked for matching conditions.
So the first method is as below where I check whether the profile ...
2
votes
1
answer
405
views
Socket Class Design C++
I am currently trying to design some C++ classes that encapsulate POSIX sockets and their relevant functions. I want to try and design classes that are simple, elegant, and make the best use of design ...
3
votes
3
answers
561
views
How to efficiently build objects without default constructors
I am trying to explain and understand a way to create object which cannot have "default" instances. Typically I want classes which represent, as closely as possible, the real-life concept I ...
1
vote
1
answer
87
views
Querying objects in a list by class type vs string identifier - Best practices
I have a class Character who has a list of Spell objects that he can cast.
abstract class Spell {
name: string
manaCost: number
abstract cast() { ... }
}
class InvisibilitySpell extends ...
0
votes
3
answers
807
views
What is the difference between these two MVC diagrams?
I want to understand what is the main difference in these two diagrams when it comes to the Model-View-Controller pattern. If there is a difference, how should I choose to construct my program? What ...
1
vote
2
answers
241
views
It is okay to create an interface of interfaces?
Let me first describe the situation
I have a component that uses dependency injection through a service locator. In the first scenario (image 1) the component needs a class that implements Interface0, ...
-1
votes
1
answer
346
views
Avoid use of the visitor pattern in this very common scenario
Let's assume we need to send a message, and to do so we would like our client to be concerned only with constructing the message (DTO) and using a facade service to send it.
We already know that we ...
0
votes
1
answer
249
views
How do we nest decorators?
It is possible to nest many decorators.
@decorator_one
@decorator_two
@decorator_three
@decorator_four
def some_silly_function():
pass
How do we write a decorator class so that the order in which ...
1
vote
0
answers
121
views
Limiting exposed interface for state transitions
Scenario: Given a class with some internal state and methods to manipulate this state, I want to limit the exposed methods that are available to potential clients/users of my API.
TLDR: In the ...
3
votes
2
answers
587
views
Creating an abstraction just for exception handling - a pattern or anti-pattern?
Assume that an external library or framework not under our control exposes a Controller API:
abstract class Controller {
abstract fun call(): Result
}
Assume that we want to handle exceptions ...
-1
votes
1
answer
117
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 = ...
2
votes
3
answers
261
views
Method that returns an object is it adequate for TDD?
Let's suppose I want to follow TDD (Test driven development) and I want to implement a class that is supposed to return a considerable object.
It starts to get really complex in my opinion and doesn't ...
1
vote
3
answers
533
views
Is in my case role based access better than permissions?
Hello StackExchange community, I'm in a bit of an impasse for my current project.
The software in question is a collaborative program designed to let employees work together on the platform and assign ...