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
3answers
251 views

Designing a class whose dependancies require “starting”/initializing step

I have Facade class which requires an Endpoint instance to function (it uses it in most of the functions). Endpoint is attached to Platform that is passed in Endpoint's constructor and has to be ...
0
votes
2answers
38 views

Should I refactor this class to use a Factory?

Given the following class in a Legacy code base without any UT's. So any refactoring done should be done on the smallest possible scale, just in order to be able to write UT's. public class Person { ...
1
vote
0answers
25 views

Need technical advice about passing data through UINavigationController

First of all a small introduction, im relatively new to Swift and to programming in general, been doing it for the last year and loving every and each new thing of this vast world. My post is about ...
4
votes
2answers
87 views

DDD Domain Modeling of Transportation Module

I am in the process of trying to model a transportation module for an ERP type system using C# and EF Core. This service is responsible for managing customer pickups and company-owned truck ...
2
votes
1answer
125 views

Dynamic Object Abilities When Saving State

I have n classes that extends from a State class, the purpose of the State class is to manage the state of the extended classes. For each class we need to save it in the database, remove it and select ...
4
votes
4answers
289 views

What kind of logic can Domain Objects realistically contain?

I have been struggling with this concept in the context of web applications ever since I first read about it. The theory states that the domain objects should encapsulate their behaviour and business ...
-3
votes
0answers
39 views

What's this pattern called? Generic Class w/ Factory to construct itself?

I stubbled upon a coding pattern while looking into some localization features in ASP.NET Core MVC. This pattern is likely only useful when using a dependency injection system similar to what .NET ...
0
votes
2answers
171 views

SimpleFactory vs Factory Method

Let's assume a SimpleFactory that creates a group of objects: public SimpleFactory { public Bycicle createBycicle(String type) { if(type.equals("ONE")) return new OneWheelBycicle(); if(...
-1
votes
1answer
43 views

Should a 3rd party user input validation library be wrapped?

Edit -- I have no limited my question down to a more specific question. Is there an argument not to wrap a 3rd party user input validation library? To me there are a few strong arguments to do so. ...
0
votes
4answers
190 views

Design pattern for a function class

I have been experimenting with the idea of function classes as explained in this article and Composition applied to function dependencies as described in the following questions: https://...
0
votes
0answers
24 views

Implementing Proxy pattern via concrete inheritance

Say I have some code which consumes a class called Subject, which implements ISubject. Would there be any concerns if I were to build a ProxySubject, which inherits Subject? I like this style because ...
3
votes
1answer
172 views

I often create class cycles by using the Observer Pattern. How can I avoid this?

I often find myself creating class cycles by using the observer pattern. Consider the following scenario: I have a central accessible global data source (Subject) The data source is reflected by many ...
-5
votes
3answers
132 views

How to Replace Many if Statements for many types

I have many statements dependence, what is the best approach to handle this cases dynamically Example enum UserType { case buyer case seller } enum ViewType { case active case ...
1
vote
1answer
93 views

How should I construct a complex object having many dependencies?

Consider the construction of the FixAcceptor type below. The code snippet is part of a unit test. var logSource = LogSource.OnMessage | LogSource.Event; var stateStore = new StateStore(); var ...
1
vote
1answer
72 views

Choosing a suitable design structural pattern for a use case

I have the following models. First, there is a Vector which has a circular DNA sequence. Second, there is a LinearizedVector which could one of below classes. LinearizedVectorBase: ...
0
votes
1answer
53 views

Transitive matching in streaming application

Problem A streaming application should perform matching transitively i.e. if A == B & B == C then A == C Current Implementation Application accepts domain objects in a streaming fashion and ...
9
votes
6answers
9k views

Which pattern to use with a typical Web Form?

I am writing a simple ASP.NET Web Forms application. I want to improve the code by implementing any design pattern with which abstraction is achieved and increases manageability and understandability. ...
1
vote
2answers
91 views

Chat part of application - using UDP or TCP?

I'm trying to build a section of my app where two users can message each other. I've read about TCP and UDP and it seems like TCP is more suited due to ordered packet delivery. However, TCP requires a ...
-1
votes
0answers
34 views

Can PHP Trait be used in any GoF pattern implementation?

I'm currently studying the original book, Design Patterns: Elements of Reusable Object-Oriented Software and tried to create an "useful" example to all 23 patterns from the four guys. As this book ...
2
votes
4answers
135 views

internal Repository that's only accessed via Service, but needed to be access via DI

I have a library that provides access to our content management. It consist of a public ContentService and an internal ContentRepository. The ContentService is public and Dependency injected through ...
-1
votes
1answer
95 views

Is there a name for this pattern of composing a type safe return type from different levels of nested related entities?

I have a problem in my app where I have many entities that can all reference each other in different ways. For example, I have a Job (e.g. build house) that I might assign to a team called "Plumbers" ...
2
votes
2answers
38 views

Beyond configuration, allowing for flexibility on a per service call basis type of pattern

Say you have a ecommerce app, and have an API call to create an order. OrderService.create(...); Order creation is a complicated process, many things will happen as a result of this call: shopping ...
51
votes
4answers
29k views

is it bad practice that controller call repository instead of service?

is it bad practice that controller call repository instead of service? to explain more: I figure out that in good design controllers call service and service use repository. but sometimes in ...
0
votes
1answer
34 views

Mapping bidirectional 'toMany' relation from DTO to entity

The application that I am working on has numerous ...toMany relations, e.i. class Model can have several parameters. In Unidirectional world, it is simple to manage a collection. I can clean the ...
0
votes
4answers
220 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
6answers
129 views

Adding client specific method to a listener interface is a good idea?

I'm using a listener pattern where a class A listens for events from various classes B, C, D with the help of a listener interface I Essentially the structure looks like: interface I { void ...
0
votes
1answer
39 views

Html development with partial views

Is it a standard practice to develop a HTML project using partial views. Consider a project where the design team will develop the HTMLs based on the requirement & then the backend team will work ...
0
votes
5answers
5k views

which pattern is most intuitive for a calculator app?

The title says it all. I'm trying to build a calculator application (for self-learning purposes). The application is going to have a very common UI, with plus(+), minus(-), multiply(*) and a divide(/) ...
0
votes
1answer
60 views

Could this be considered a valid State GoF Pattern implementation?

For teaching purpose, I would like to create a simple implementation of State Pattern using PHP 7.4. So, I've tried to create a simple "document state machine" starting with Draft, sending to review ...
2
votes
3answers
275 views

How to compile to multiple target languages

Sidenote, just learned about Haxe which may offer some insight into this question. The basis of my question is what sorts of tradeoffs (if any) need to or must be made if you wanted to compile one ...
1
vote
1answer
47 views

Building a form based on json object?

I'm currently refactoring an older legacy application and use React to rebuild some of the former functionality. This application has a form which has +10 different input fields. The aim is to kind of ...
1
vote
1answer
120 views

Should I use Factory Method design pattern for this problem?

I'm working on an application which needs to open a database file. There are 2 "versions" of this database: one of them is more general data storage, and the other contains "less" information. That ...
0
votes
1answer
49 views

How to design a repository when datasource differs based on DML/READ operations?

We are starting our new application in which we using MS SQL DB for all our insert/update/delete/select ie. both SELECT and DML operations. But, soon we will have two different sources. SQL Server ...
0
votes
0answers
54 views

Dao pattern Java and Hibernate

I am trying to create a good pattern for my application. I want to reduce as much as possible the duplicate code and I want to use generics as much as possible. I have created a pattern for this but I ...
-4
votes
0answers
29 views

In Kafka Streaming, is`StreamsBuilder` a builder class?

In general, a builder instance is used in the following way: builder.buildPartA(); builder.buildPartB(); co = builder.getResult(); In Kafka Streaming, isStreamsBuilder a builder class? For ...
1
vote
0answers
61 views

Best way to check if a value meets a condition and then perform additional logic based on the condition it meets?

I'm curious if there is a pattern or at least a better way to code this situation. For example, say you're writing a rest api for a reporting workflow. You have a User class and a Job class. Each User ...
0
votes
1answer
118 views

Name of this enum-based design pattern to get the type

I have been using a pattern in a lot of places (mainly C#) that I would like to know the name of. Here is an example of it in C#: public enum ThingType { A, B, C } public interface ...
3
votes
7answers
1k views

design pattern for conditional behaviour depending on a client ID

I don't know if there actually is one design pattern, or several together, or maybe what i'm asking is anti-pattern. Context (simplified) : my company sells SaaS services (through an API) to several ...
144
votes
6answers
226k views

What is the point of using DTO (Data Transfer Objects)?

What is the point of using DTO and is it an out dated concept? I use POJOs in the view layer to transfer and persist data. Can these POJOs be considered as an alternative to DTOs?
0
votes
3answers
179 views

A case when you can't make processing idempotent

I have just been confirmed for an interview and one of the hint questions given by the recruiter was: "Explain Idempotency and a case when you can't make processing idempotent" I understand ...
1
vote
1answer
147 views

Can Value Objects create their own value?

Let's say you have a username value object which has formatting rules e.g., class Username { private $username; public function __construct(string $username) { // thrown an ...
0
votes
2answers
63 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 ...
-4
votes
0answers
38 views

Which design pattern for logging implementation with c#? [duplicate]

I want to implement logger class library with c#. But I don't know which design pattern works best. Abstract factory or singleton and or etc.
0
votes
1answer
481 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 ...
-5
votes
0answers
46 views

Specific Design Pattern required

At an interview for aws I was first asked to extend the functionality of a email class that forwarded an email based on specific subject variables for the class or in another case if the specific ...
1
vote
1answer
46 views

Is this form generator a valid Composite GoF?

Searching for a good PHP real world example, I've found this example of "composite" using: FormElement as Component Fieldset and Form as Containers Input as Leaf (this is my UML from the code): ...
2
votes
1answer
105 views

Is this a valid GoF Adapter example?

After visit dozens of pages searching a "non-sockets-or-iphone-conceptual-example" of Adapter Pattern, I have found this one: Lloyds bank is an international bank offers services worldwide. For ...
2
votes
1answer
119 views

Is there a simpler approach than abstract factories for handling similar, but branching, logic?

I have a medium-sized Angular-based web application that I'm currently implementing some permission components for. Overall, the areas where the permissions components will be used are virtually ...
21
votes
4answers
4k views

Constructing an object: should I expose or hide parameters passed to the constructor?

I've a habit I just mechanically do without even thinking too much about it. Whenever a constructor is waiting for some parameters, I consider this a public information that should be available by ...
7
votes
6answers
742 views

Strategy vs Factory design pattern

I am new to design patterns and working my way through the Factory Method and Strategy patterns. I understand that Factory is a creational pattern and Strategy is behavioral but I struggle to ...

1
2 3 4 5
76