32,137 questions
Best practices
0
votes
3
replies
65
views
Can a Composite Component class inherit from another abstract base class without breaking the Composite pattern?
I’m studying and implementing the Composite design pattern in C# for a university project.
In most textbook examples (GoF, Refactoring.Guru, etc.) the class hierarchy looks like this:
Component
├── ...
Best practices
0
votes
0
replies
44
views
Testing in MVVM architecture. What to test and how to approach TDD?
I’m currently working on a personal Android project using Kotlin and Android Studio, following a basic MVVM architecture:
─main
│ ├───java
│ │ └───com
│ │ └───example
│ │ └───...
0
votes
0
answers
80
views
How to register function delegate with interface that has a generic type?
I wanted to create a flexible MessageProcessor, depending on the SupplierType(= enum) and depending on which MessageProcessor comes out a different Message-object will be used.
The current situation ...
1
vote
0
answers
67
views
How to provide type-safe factory functions for dynamically registered classes in Python?
TL;DR
Suppose a Python library defines an interface meant to be implemented by third-party code. How could this library provide a factory function that creates instances of those implementations, with ...
Advice
0
votes
0
replies
25
views
Designing a props-driven test framework for data quality validation - best patterns?
Question: I'm building a testing system for a data quality SaaS app where tests are entirely props-driven (similar to React component testing philosophy).
Goal: Create reusable, composable test ...
Best practices
3
votes
1
replies
107
views
Architecture design for multilingual descriptions for several classes
I am creating an E-Commerce app. It has Category and Product classes. Both have multilingual descriptions, so, tables with title, description, meta-*, etc. and unique key (id, language_id).
To add ...
2346
votes
40
answers
741k
views
What is Inversion of Control?
Inversion of Control (IoC) can be quite confusing when it is first encountered.
What is it?
Which problem does it solve?
When is it appropriate to use and when not?
2096
votes
41
answers
697k
views
Difference between static class and singleton pattern?
What real (i.e. practical) difference exists between a static class and a singleton pattern?
Both can be invoked without instantiation, both provide only one "Instance" and neither of them is thread-...
2387
votes
24
answers
584k
views
What are MVP and MVC and what is the difference?
When looking beyond the RAD (drag-drop and configure) way of building user interfaces that many tools encourage you are likely to come across three design patterns called Model-View-Controller, Model-...
1492
votes
26
answers
724k
views
What is the difference between MVC and MVVM?
Is there a difference between the standard "Model View Controller" pattern and Microsoft's Model/View/ViewModel pattern?
1152
votes
30
answers
131k
views
Does functional programming replace GoF design patterns?
Since I started learning F# and OCaml last year, I've read a huge number of articles which insist that design patterns (especially in Java) are workarounds for the missing features in imperative ...
490
votes
48
answers
403k
views
Simplest/cleanest way to implement a singleton in JavaScript
What is the simplest/cleanest way to implement the singleton pattern in JavaScript?
5
votes
2
answers
198
views
Improve implementation of a "widget tree structure" in Qt6 [closed]
Let me introduce first the problem. I will present a simplification of my QT6 project app (in C++) to not make it too difficult to read, as the original code has lots of unnecesary things for this ...
858
votes
29
answers
345k
views
What is an efficient way to implement a singleton pattern in Java? [closed]
What is an efficient way to implement a singleton design pattern in Java?
575
votes
31
answers
234k
views
Dependency Injection vs Factory Pattern [closed]
Most of the examples quoted for usage of Dependency Injection, we can solve using the factory pattern as well. Looks like when it comes to usage/design the difference between dependency injection and ...
559
votes
21
answers
517k
views
Is there a simple, elegant way to define singletons? [duplicate]
There seem to be many ways to define singletons in Python. Is there a consensus opinion on Stack Overflow?
0
votes
0
answers
45
views
Singleton pattern in Rust [duplicate]
Goal
Implement a Singleton Design Pattern for a struct, without multiprocessing considerations.
Minimal example
Here is the base of the code, without the singleton logic.
struct ...
574
votes
24
answers
338k
views
On design patterns: When should I use the singleton?
The glorified global variable - becomes a gloried global class. Some say breaking object-oriented design.
Give me scenarios, other than the good old logger where it makes sense to use the singleton.
2
votes
0
answers
213
views
Design dilemma with enum_dispatch in Rust
I'm designing my system which consists of three parts, abstract layer (al) where traits and generic data structures are defined; implementation layer (il) where different structures implement traits; ...
527
votes
19
answers
276k
views
What is the difference in case of intent and application between these two Patterns? [closed]
Factory and Abstract Factory are both creational patterns.
What is the difference in case of intent and application between these two Patterns?
618
votes
13
answers
308k
views
When would you use the Builder Pattern? [closed]
What are some common, real world examples of using the Builder Pattern? What does it buy you? Why not just use a Factory Pattern?
168
votes
34
answers
389k
views
Function in JavaScript that can be called only once
I need to create a function which can be executed only once, in each time after the first it won't be executed. I know from C++ and Java about static variables that can do the work but I would like to ...
6
votes
2
answers
152
views
How can I generalize a unit conversion method for different Enums in Java?
I’m currently building a unit converter app in Java (as a beginner), and I want to avoid duplicating logic for each type of unit.
Right now, I have different enums like Length, Weight, Time, etc., and ...
1
vote
1
answer
151
views
Can template tag be inside template class itself?
I have a templated class Bounded which have parameters:
fundamental type
Min value allowed
Max value allowed
policy (wrap, limit)
I can do it if the struct defining policy is defined outside the ...
517
votes
21
answers
258k
views
MVC pattern on Android
Is it possible to implement the model–view–controller pattern in Java for Android?
Or is it already implemented through Activities? Or is there a better way to implement the MVC pattern for Android?