Stack Exchange Network

Stack Exchange network consists of 175 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 [design-patterns]

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

0
votes
1answer
68 views

Should there not be methods intended to be only called from inside of the package, but from the outside of the class they're defined in?

Note: This is a follow-up to this question on StackOverflow. I have to write a wrapper in Python to an external API, accessible through HTTP. The code is supposed to be publicly available on GitHub. ...
-2
votes
1answer
93 views

What's the best design pattern approach for introducing optional feature to current code base?

I had a class hierarchy with several classes that interact with each other. After introducing new feature that is optional (but it depends on external libraries) I have the following code (just ...
2
votes
3answers
102 views

Design: Where should methods specific to a model, but not an instance go?

Let's say I have a User model defined. It makes sense that methods for retrieving certain fields of this model lives in the model file. My question is where something that generates a unique UUID, or ...
-1
votes
1answer
60 views

How to build a custom intermediate operation pipeline in Java for a series of API calls? [on hold]

I am working on a project which provides a list of operations to be done on an entity, and each operation is an API call to the backend. Let's say the entity is a file, and operations are convert, ...
0
votes
0answers
111 views

Decorator Pattern Java

This is an object-oriented design question that is specific to Spring Boot. I'm extending a Spring Boot application that has an interface that is being extended and used inside another service. The ...
1
vote
0answers
46 views

How to solve circular dependency scenario while executing http calls which require authentication?

I am working on a project which requires me to execute standard HTTP calls with session tokens. I am building a custom HTTP client, with a custom authenticator, something like this: Client client = ...
0
votes
1answer
79 views

Is singleton use acceptable for static single responsibility?

I have been reading into possible design patterns and have found the use of singletons always referred to as an anti-pattern. I am currently using a singleton for the sole purpose of gathering ...
3
votes
2answers
263 views

Should Entity Framework 6 not be used with repository pattern?

So I am asking this after reading the following: Why shouldn't I use the repository pattern with Entity Framework?. It seems there is a large split of people who say yay and those that say nay. ...
0
votes
0answers
47 views

Best practice for Asynchronous CRUD operations in Android/Java

A few months back, I was working on designing a client API (FooManager) for adding/removing/fetching a list of objects (Bar). The requirements were simple- 1. Fetch operation is CPU-intensive and ...
0
votes
0answers
45 views

How would design a wrapper for a large, multi-response api like the one described below?

Let me explain. Lets say there exist some service at some organization that exposes information on a company's assets, from employees company-issued devices(laptops and issues) to the the large xerox ...
0
votes
2answers
54 views

Architecture/design for reading incoming data and distributing it across program

This may be a broad question but I have not been able to find an answer. In my program I am communicating to a device over serial communication. The data coming through is binary, and formatted with ...
11
votes
6answers
518 views

DDD meets OOP: How to implement an object-oriented repository?

A typical implementation of a DDD repository doesn't look very OO, for example a save() method: package com.example.domain; public class Product { /* public attributes for brevity */ public ...
0
votes
0answers
56 views

Generic Message Queue Interface

I'm trying to implement an Interface for a Message Queue. This interface should allow different implementations of queues to be implemented etc AWS SQS, Azure Queue Service. So lets say that I have ...
0
votes
1answer
101 views

Factory Design Pattern Implementation with multiple interfaces and base class

I know it is lot of code. But I am trying to understand the concept of Factory pattern with interfaces and base class. I have a base class of Car that implements an interface which will be implemented ...
0
votes
3answers
84 views

How can I do a step based design form my applicaiton?

I want to create an application that has some optional steps. But I could not decide how to do step plans. It looks like a workflow. I have a Work entity. This work includes specific business steps. ...
1
vote
0answers
44 views

Strategies for dealing with Stale data and Fetching

I'm working with firestore and have encountered several situations where a document will contain stale data which is a duplicate of the source of truth located elsewhere in the database. For ...
0
votes
0answers
27 views

Using Autofac (or any IoC) to customize a core product?

We are trying to implement a plugin system where a Customer Project can override small bits of a Core Project in order to make the app custom to a specific customers requirements.. We are working with ...
0
votes
2answers
75 views

How to design classes of a self-driving machine, if I need a simulation?

Background: I'm working on a project with a self-driving machine with a tank-like control, somehting like: forward() left() right() stop() The code is running on a raspberry pi. The GPIO outputs are ...
0
votes
1answer
142 views

Keeping steps in sync of long running process and creating common layer for code repetition

I have 1 long running process wrapped inside a method and it is for 2 different types like below: Type1 Type2 Code: public interface IBaseType { MyResult LongRunningProcess(int jobId,...
8
votes
4answers
726 views

What is “premature abstraction”?

I've heard the phrase being thrown arround and to me the arguments sound completely insane (sorry if I'm strawmaning here, Its not my intention), generally it goes something along the lines of: You ...
0
votes
2answers
75 views

Designing a modular CLI tool

I am building a CLI tool which will potentially support many commands. Ideally, I want to abstract out each command to implement an interface that demands a "run" method. From there on, it would be a ...
0
votes
2answers
90 views

How to design an API wrapper with bulky operations on domain object? (Need guidance)

I need some guidance in designing an API wrapper for my backend APIs. I have tried to keep it as specific as possible. Context: We have a project which supports certain file operations like edit, ...
0
votes
1answer
84 views

What design pattern would help me make my factory more generic

In my code I have 2 separate login types. I have a factory that decides which one to create based on an enum. Each login type has a different type of credential. Currently my factory method takes ...
3
votes
1answer
183 views

Understanding interface injection

Quoting the definition of interface injection from Wikipedia : The advantage of interface injection is that dependencies can be completely ignorant of their clients yet can still receive a ...
3
votes
2answers
164 views

How to prevent overlap booking on a calendar booking system

As an exercise, I am trying to design a simple calendar booking system for multiple meeting rooms. I kind of got my head around some requirements such as find available rooms for a given time range, ...
2
votes
1answer
55 views

How to indicate to backend that model need be updated or created new?

There's a complex model which represented by complex JSON with multiple fields and nested objects. Recently we have discussed in which way indicate to the backend that the object needs to be saved as ...
2
votes
3answers
168 views

Design - What is the best way to separate functionalities?

I recently worked on a file explorer within a console window (like Midnight Commander). I want to use ncurses as library. I have encountered some fundamental problems with my design and searched on ...
0
votes
0answers
69 views

Is using IoC with data classes a good practice

I usually use IoC frameworks to inject dependencies that are services. Is it ok to mark classes that are data objects as IoC components? To be more clear I will give an example. I have an abstract ...
0
votes
0answers
68 views

Combination of visitor and iterator pattern

While studying the visitor design pattern i found this phrase: You can use Visitor along with Iterator to traverse a complex data structure and execute some operation over its elements, even if ...
1
vote
1answer
68 views

Is this code a wrapper or an adapter?

I´m using a framework for javascript to display beautiful alert boxes. This framework uses another framework to actually display the boxes. So it´s something like that: let showAlert = function (...
0
votes
0answers
52 views

Linear “steps” of operations considered a state machine?

I have a set of tasks I perform to complete some larger operation. These tasks must be executed in linear order, and you cannot proceed onto the next task until the previous completes. For the most ...
2
votes
3answers
277 views

Do language features affect the use of dependency injection?

I've been looking into dependency injection, what it is, how it works, how it's being used. It's a neat system and to understand it a bit better, I'm going to implement a small demo app using this ...
-1
votes
1answer
57 views

Node.js / Express.js - Route consisting almost entirely of middleware

Is it a bad design pattern / anti-pattern to create a whole bunch of specific middleware to replace functions in-route. So instead of doing this router.post('/myRoute', (req, res, next) => { ...
0
votes
2answers
59 views

Managing multiple dynamic database connections

I'm working on a server, which you can pass some form of authentication as input (like connection string) and it will connect you to your database. So the DB connection is going to be dynamic. There ...
0
votes
1answer
69 views

Is a JSON wrapper an adapter?

Please let me illustrate with a simple example. Suppose we have a Weather object: class Weather: def get_forecast(self, day, place): forecast = "code that calculates forecast" ...
0
votes
1answer
63 views

how to ensure consistency for concurrent requests for same mutable data?

Consider an abstract example, just to illustrate - you have a service for loans, which gets requests to borrow X USD, checks if there’s enough USD to lend that, if yes - marks that amount as reserved ...
6
votes
5answers
339 views

Design pattern for 2 methods one has 70% arguments of other one

I am trying to do a design for notification part in the system I have 2 parts inApp notification and email notification so I used strategy pattern where I have interface NotificationSender with one ...
1
vote
3answers
164 views

Builder pattern: How to verify required fields before runtime

A language agnostic approach since I see this problem in both compiled and interpreted languages with the builder pattern. Let's say I have a Model that has 10 required fields and 5 optional fields. ...
2
votes
5answers
254 views

Which layer should have responsibility for rounding numbers?

I am developing a financial system and want to have a defined policy for rounding monetary values. Given the following layers: View API Entity Model Persistence If I am passing a monetary value ...
0
votes
5answers
210 views

Design Pattern for object that asks questions of another object

I'm looking for a design pattern that might work for this class I am working with. This main class is an entity using Domain Driven Design. public class TimeCard() : ITimeCardHeader { ...
0
votes
2answers
85 views

Is this a proxy or bridge or something else?

I have an object that acts as a "bridge" between objects and I'm not really sure if it has a name. Unity (the game engine) lets me build a concrete object and then link those objects in the inspector ...
1
vote
1answer
155 views

Why read and write API are good or why not?

While designing a complex system some of my colleges came back with the idea of having two separates APIs, one that will perform the writes into de databases and another one that will only do the ...
2
votes
1answer
239 views

C# .Net Core API design - interfaces vs DTOs

I'm designing a relatively simple web application using .net core. I've mostly done desktop development in my career so far, so I'm a bit new to the nuances between desktop and web development. In ...
-1
votes
1answer
61 views

Patterns for loading related objects in memory (without an ORM)

I am using ADO.NET to read a bunch of data from the database into in-memory objects. This is my domain model: // Question.cs public class Question { public int ID { get; set; } public ...
0
votes
2answers
133 views

Force field initialize not by constructor in c++

My parent class has a vector field I want to force child classes to push in that vector as many as items they have. At least one item example: class Options { protected: vector<...
1
vote
0answers
45 views

When not to use View Services in MVVM design pattern?

I'm using the MVVM design pattern in my application which is comprised of, A Xamarin.IOs project (View Layer) A Net Standard project (Common Layer) A Xamarin.Android project (in the future) (View ...
3
votes
2answers
130 views

Design pattern for similar classes that require different implementations

Edited: Update is at the bottom There could be a common or best practice for this scenario, but I am unfamiliar with it. However, it could very easily be a matter of subjective opinion on how one ...
1
vote
0answers
24 views

Spring Boot and Mustache app separation of concerns

I am wondering how best to slice up a Java Mustache web app which has: Data layer (JPA, Repos, Entities, etc) Service layer getting data from other company web services outside the package Web/...
0
votes
1answer
94 views

Do I include system dependencies when calculating Instability?

Given the formula to calculate instability... I = (Ce / (Ca + Ce)) with Ce = outgoing dependencies, Ca = incoming dependencies, and I = Instability, ...should I include system dependencies (such as ...
0
votes
1answer
43 views

Should libraries be packaged together based on similar traits?

I just started a new job and one of my first tasks is to create local nuget packages from the existing libraries, to help with versioning, maintenance, etc. This task had already been started by ...