Category "design-patterns"

Inappropriate Intimacy in factory

My Factory has dependency on Repository. It calls many methods from Repository. Lets say something like this: class CarFactory { private Repository reposito

How to test laravel controller method?

My controller looks like this: public function store(Request $request) { $validateData = $request->validate([ 'name' => 'required|u

How to use the second parent class methods which is inheriting from an interface in python?

I am trying to implement an interface and this interface is taken by two concrete classes say class First and class Second, I have another class that takes thes

DDD Application Layer and Persistence Transactions

Leaders in DDD cite the Application Layer as the appropriate place for Transaction Management. For example, from Vince Vaughn: Application Services reside in t

CQRS, Is it bad practice using the same class/model for write and read

So let's say I have a product order system. I have several classes that may look like this. data class CreateOrderCommand( val productId: String, val produ

Difference between method chaining and fluent interface

I wanted to know the exact difference between method chaining and fluent interface. As I understand it, method chaining is just running the methods of previous

What is the best practice to construct a Domain Object depending on external calls?

I am trying to build an object that gets its data from external APIs. I will try to explain it with an example: First of all, I get a POST body in my API to cre

Fluence Builder Inheritance with Recursive Generics

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Creational.Builder { public c

Good practice / design pattern to resolve the nested if else?

Currently I have code like this: for (each item) { if (item == 'x') { print } if (item == 'y') { print } } Now, there is an additiona

Swift Singleton Pattern in Conjunction With Cloud Firestore

I have been looking into cloud firestore as my backend infrastructure. Ive been using realtime database but feel the switch is vital. I have looked at the fireb

Cyclic transfer of Object

I'm trying to model blood flow. As simple as it gets I am trying to have an event (TimerTick) trigger the transfer of a resource object from unit A to unit B, B

Where is the Balance Between Dependency Injection and Abstraction?

Many Architects and Engineers recommend Dependency Injection and other Inversion of Control patterns as a way to improve the testability of your code. There's n

Using Template Method and Strategy together

Gang of Four sums up the difference between Template Method and Strategy as follows: Template methods use inheritance to vary part of an algorithm. Strat

Best practices in block based or flow based system programming [closed]

I'm trying to implement a Labview-like system (in Java) where some blocks are capable of - Sourcing - Sinking - Passing-through the data. Eve

Is UnitOfWork equals Transaction? Or it is more than that?

The internet is full of information about UnitOfWork pattern; even SO is not an exception. I still do not understand something about it. In my understanding Uni

Big configuration object as a parameter in Swift?

In JavaScript/TypeScript, we have this pattern that is often used in libraries where you have one optional parameter as the last function argument which default

Interface Method with different type of arguments

I'm constructing a set of filter-classes which will all have the same method 'Applyfilter'. How should I define the interface which contains apply filter? The o

Reasons for and against objects handling their own persistence [closed]

I am looking at different options for persistence modelling in Windows Phone using Isolated Storage. One of the ideas I have come up with was

How to pass context in golang request to middleware

I am trying to understand how the context introduced in Golang 1.7 works and what would be the appropriate way to pass it to middleware and to a HandlerFunc. Sh

What is the exact difference between Adapter and Proxy patterns?

As I understood both Adapter and Proxy patterns make two distinct/different classes/objects compatible with each for communication. And both of them are Structu