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
0answers
4 views

How to define Composition Roots for libraries (Javascript/inversify)

I'm building a console app (A), which depends on library B. Library B further depends on library C. I am building all 3 entities. Most of the development completed so far has been done using a ...
0
votes
2answers
67 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 ...
3
votes
3answers
96 views

Is this a good method of separation?

I am creating a web application that is tiered in the following way: Controller > Service > Repository I have a ProductsController which has the following action: [ValidateModel] [HttpPost] public ...
-3
votes
0answers
37 views

Are my UML's understandable and do they follow the UML conventions?

I'm new to software modeling and was hoping someone could walk me through mistakes I've made. I'm trying to show how my parser for our game is working. Said in words, the parser is supposed to take ...
0
votes
2answers
98 views

Is this a proxy or bridge or something else? [on hold]

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 ...
-3
votes
1answer
62 views

Taking over a project. Should I scrap and rebuild? [on hold]

I'm taking over an Opencart solution for a client. This is for my capstone at College. I'm to create a simple CRM (Customer Relationship Management) software that will live as a single page ...
0
votes
0answers
25 views

Handling resumable message stream (queue) pattern

My question is actually quite generic though I'm going to use a particular technology Mongodb Change Streams. Change streams in Mongo allow to get message stream of requested changes in a db ...
0
votes
1answer
201 views

Can a class factory also save the object to a database?

How can a factory also save the object in the database? I want to create an object that consists of other objects. Pseudocode: firstObject = db.get....; secondObject = db.get....; expectedObject = ...
1
vote
1answer
77 views

Functionality design: Multiple sources, multiple consumers with configuration

It is a Design Problem which I am listing out here. I have multiple event sources in my app, each one produces events with the different set of data (but each source is producing only one type of ...
4
votes
1answer
216 views

How to set up a sql database to cater for user records, group records and default records?

Outline I have an application that loads data from a database. I'm not talking about client data here though, I'm talking about application configuration. The database will therefore come with some ...
8
votes
5answers
2k views

Can we completely replace inheritance using strategy pattern and dependency injection?

For example: var duckBehaviors = new Duckbehavior(); duckBehaviors.quackBehavior = new Quack(); duckBehaviors.flyBehavior = new FlyWithWings(); Duck duck = new Duck(DuckTypes.MallardDuck, ...
-2
votes
0answers
15 views

Processing app - 2 way interaction? [on hold]

I am trying to choose a framework (.NET Based - Core/Standard) in order to create an application that will gather data from multiple clients, process the data and send it to other clients. The App ...
2
votes
2answers
1k views

JavaFx : Is there difference between String and StringProperty in Model Classes?

I'm trying to follow MVC concepts when i develop my application ,but I'm confused between Using String or StringProperty in Model classes. Example one : public class User{ String name; ...
1
vote
1answer
101 views

Why using ViewModel when using also Repository?

I read this guide about recommended app architecture for Android. Here is a graphical summery: The role of ViewModel is clear, but I don't understand why we need it if we use Repository. The purpose ...
-2
votes
1answer
90 views

What name would you give to this class design? [closed]

I have inherited a legacy code base and see a lot of classes that implement methods in the following way. class InvoiceCreateService { private $order; // Domain object public function ...
54
votes
7answers
24k views

Is dependency injection essential for unit testing?

Is using dependency injection (DI) essential for unit testing? I can't think of another alternative for isolating code so it can be tested. Also, all the examples I have ever seen use this pattern. ...
-1
votes
0answers
44 views

How to share/synchronize information between low level classes application-wide [closed]

We have a page-based application that is moderately large and contains multiple render views on different pages. The views are quite well encapsulated, and each have a 'tool-based' architecture where ...
0
votes
1answer
28 views

What is a good strategy for managing PubSub subscriptions

I am working with Reddis but this could apply to any PubSub implementation. Essentially we are trying to implement an event system using Reddis's PubSub capabilities. As an example UserA creates a ...
6
votes
6answers
477 views

I need help solving a common architectural problem with multiple concrete classes implementing an interface

I have a common issue I encounter which I've solved with a Factory class in the past but it always felt a little "off". Let's say I have multiple Exporter classes which implement IExporter, which has ...
0
votes
2answers
66 views

What are the relations between the presentation/application/data logics, client and server, and MVC?

I appreciate if someone could clarify my confusions about the following quote from Distributed Systems, by Coulouris et al: Consider the functional decomposition of a given application, as ...
0
votes
2answers
35 views

Force State changing of an Object only from Holder

Suppose I have a Button class with a color attribute. I also have a Canvas class which stores all Buttons. Every time a color is being changed, some side action must take place (in this example, for ...
0
votes
1answer
104 views

Relating subclasses of two classes

Suppose I have the following problem: I have Users who work in Departments. A user can work in multiple departments and a department can have multiple users. Each departament gives to its users only ...
2
votes
3answers
345 views

Different Redis instances for different microservices?

Say that we have Kubernetes running with n pods, each being a separate microservice. Now, some of those services need a caching layer. When we take into consideration: the fact that Redis was tested ...
0
votes
1answer
51 views

Update Entity for Repository Pattern and UOW Pattern C#

In one mock solution, I have created 3 mock projects to implement layered architecture design mainly the - Presentation Layer (Web) - Domain Model Layer - Infrastructure Layer. I haven't yet to add ...
0
votes
1answer
25 views

Venue Reservation System Logic Approach/Clarification

I hope this is the right place to ask since this is a programming related question. I’m developing a venue reservation app (similar to booking.com) and am almost done however I have 1 request for ...
0
votes
1answer
43 views

How to associate tree nodes with other objects before they have unique identifiers

I've been thinking about a simple software design problem. Imagine I am writing a web application to edit a tree of objects. Each node of this tree has an ID property that is filled in when the node ...
2
votes
4answers
2k views

What is the difference between Strategy Pattern and Dependency Injection?

I was reading "Beginning Spring" and this particular paragraph caught my attention: The DI pattern resembles other patterns such as Factory or Strategy. We can say that with the Factory pattern ...
2
votes
1answer
140 views

Design pattern for an indeterminate number and format of questions [closed]

In my application, I have a finite number of question types, but the order in which they're asked and whether they're asked at all is not known up-front. An example analogy is a hotel booking process,...
1
vote
1answer
104 views

Contract based programming with verifications

I have a large project that is build contract based, where all functions verify input parameters and return values. But there are also cases where they for example verify that a call to a function is ...
4
votes
1answer
421 views

Handling common code among presenters

I'm facing some issues related to code duplication when following MVP architectural pattern in an Android project that I'm working with. My project structure is separated by packages: data, domain, ...
4
votes
3answers
368 views

Pattern for endpoint that routes requests?

I am building a service that will push notifications to many other services. It has a couple of different notification types that each consumer may care about, but likely will not care about all of ...
0
votes
6answers
2k views

How to change the state of a singleton in runtime

Consider I am going to write a simple file based logger AppLogger to be used in my apps, ideally it should be a singleton so I can call it via public class AppLogger { public static String file = ...
0
votes
1answer
71 views

Structuring PHP classes that need to return multiple objects

I am trying to plan out php class structure for an order processing project. I've used classes before but I'm still not an expert on OOP yet. I've been searching for hours and can't seem to find the ...
2
votes
1answer
88 views

Microservice API Design Pattern

I'm new to the application architecture world. I walked through Docker's sample voting app, and see that basically everything that can be made into a modular piece, is made into one. I'd really like ...
6
votes
2answers
2k views

Repository pattern implementation that knows nothing about the database table and column names

I've seen around the Internet and Github, implementations for the design pattern Repository that knows about database table and column names. I was think, if I want to work with the database as a ...
0
votes
1answer
72 views

REST API Client Library Design

I'm working on a reusable client library to abstract a REST endpoint that we use in many of our in-house applications. It is actually split into 3 APIs, and certain endpoints/resources require ...
0
votes
1answer
81 views

Appropriate pattern for injector that sets a property and client that ONLY gets a property

Suppose I have a method in client code that expects an interface... void DoWork(IDataManager data) { //use IDataManager interface in the DoWork method } And the IDataManager interface looks like ...
2
votes
2answers
143 views

destroy object once it won't be used anymore in flyweight pattern

I want to use flyweight pattern to return the same instance of my object each time. public class ThingFactory { private static final HashMap<UUID, Thing> things = new HashMap<>(); ...
2
votes
1answer
276 views

Two-level concepts

I find myself lately implementing the same concept twice, once at a low level and once at a higher level. Let me see if I can explain it... For example, given the notion of a database, I have one ...
0
votes
1answer
182 views

Handling Different Parameters for Derived Classes

I'm designing an API and I ended up having a few pure abstract classes. Because of the nature of the problem that I'm solving, each derived class has to be initialized with different sets of ...
0
votes
0answers
31 views

Is Unity Container Property Injection following Bridge Design?

I have following code written on top of Microsoft Unity. This is the implementation of property injection. I recently gone through a Bridge Design Pattern that separates abstraction from ...
1
vote
1answer
79 views

How to design a wrapper for a large, multi-response API?

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 printers on ...
229
votes
15answers
97k views

Do I need to use an interface when only one class will ever implement it?

Isn't the whole point of an interface that multiple classes adhere to a set of rules and implementations?
0
votes
2answers
130 views

Design pattern for wrapping multiple apis into single api

I have 3 different libraries that provide depth data as well as gesture information. I need to wrap these libraries into a single simpler to use for user api. The apis I am trying to wrap provide a ...
5
votes
5answers
2k views

Pitfalls of Domain Driven Design with Entity Framework

A lot of tutorials on DDD I studied are mostly covering theory. They all have rudimentary code examples (Pluralsight and similar). On the web there are also attempts by a few people to create ...
4
votes
3answers
501 views

Should I use the Factory Pattern when instantiating objects with very different constructors?

Let's say (just for the sake of example) I have three classes that implement IShape. One is a Square with a constructor of Square(int length). Second is a Triangle with a constructor of Triangle(int ...
0
votes
2answers
185 views

Java Design for Data enrichment based on logic defined in a database

I have the following requirement. Read data from a messaging Queue and process each message to enrich the message and then finally send the enriched message to a different system. The enrichment ...
0
votes
4answers
296 views

Is Template design pattern a bad practice due to inheritance?

I have been using Template Design pattern in my code for implementing CRUD procedures for different resources. There are some steps which are same for many resources and some which need some addition/...
0
votes
1answer
138 views

Onion Architecture - Multiple Apps

Onion Architecture talks about separating the UI, Service, and Data Layers. All the samples usually given for this involve a single deployment model of the application. For example in .net most of the ...
2
votes
1answer
171 views

How can I allow interaction between user-only modules & admin-only modules without polluting with privilege checks?

Important note: This is PHP (5.3+). PHP is stateless and everything you do dies when the request is over unless saved to a persistent storage, but if the answer provided gives me pseudo-code, I'd also ...