316 questions
1 vote
2 answers
68 views
How does the Liskov Substitution Principle works with type specialization in concrete implementations of abstract classes?
Suppose we want to model different kinds of food; pizzas and pies. Both pizzas and pies do have a sort of topping, but their toppings are different. We implement an abstract class Baked, and two ...
3 votes
1 answer
288 views
Difference between REP(Reuse/Release Equivalence Principle) and CRP (Common Reuse Principle)
Can someone please explain the difference between REP and CRP to me? I understand that the CCP (Common-Closure-Principle) states that modules that need to be changed together frequently should belong ...
0 votes
0 answers
43 views
Is it a good practice to define datatypes in `__init__.py`?
I have a folder structure like this: nlp ├── generation │ ├── io_operations │ ├── __init__.py │ ├── generator.py │ ├── processing.py │ └── prompting.py │ ├── prompts (folder) │ ...
0 votes
1 answer
162 views
How to prevent coupling between our code and third party libraries?
Imagine we want to use the following library like this: use GrahamCampbell\GitHub\GitHubManager; class Foo { private GitHubManager $github; public function __construct(GitHubManager $github) ...
0 votes
0 answers
34 views
Is there a principle "inverted" to single responsibility? I.e. to collect all responsibilities related to certain task in one place?
Example 1: You're designing an object and you put all the things and configurations required for it to work into the constructor call, so no additional calls needed after it initialized. Example 2: ...
2 votes
1 answer
78 views
How should I use Factory method design pattern that follows Dependency Inversion Principle
I've created a command like this, but I would like to refactor it to follow the DI principle: public function handle() { $productChoice = $this->argument('product'); if ($productChoice == ...
0 votes
2 answers
99 views
Is it bad practice to mix SubTyping and Overriding?
Please correct me of any of statements in this thread are wrong. I read that reusing code is the primary benefit of inheritance, but it dawned on me that polymorphism through subtyping is the primary ...
0 votes
0 answers
57 views
“Never alter or delete a user’s work without them knowing” - is there a name for this software design principle?
Is there a software design principle that says an application should never alter or delete a user’s work done in the application without them knowing? It’s very similar to the Principle of Least ...
1 vote
1 answer
90 views
Design pattern for encapsulation of functions that draw / write an object
My specific case is a web application but I believe this would apply more generally: I have data stored remotely in a database. My application uses 'collection' objects that correspond to each table ...
7 votes
6 answers
13k views
When should I throw exception vs. return error ActionResult in ASP.NET Core Web API project?
I am making an ASP.NET Core Web API project with controllers. All API controllers derive from ControllerBase that has NotFound() method. I use this method from controllers whenever I can't find a ...
1 vote
1 answer
1k views
Spring application events without extending ApplicationEvent
Is there any way to define custom application events without extending ApplicationEvent? We are having submodules based on ports and adapters principle, domain module not having any any external ...
-1 votes
1 answer
48 views
When we use class methods as setter to input object
What principle are we violating if we use a method to update an input object's fields? An example: class Data { public int $someField = 0; // it's private with setSomeField method public int $...
1 vote
3 answers
160 views
How to implement the Open-Closed Principle in error handling for new error types?
In the given JavaScript code snippet, there are two functions - handleClientError and handleServerError - that handle client-side and server-side errors, respectively. The handleError function is used ...
0 votes
1 answer
139 views
Identify the best architecture for sending different types email in ASP.NET Core
I have defined an interface IEmailManager as having send method. The email controller is using its concrete type EmailManager as a constructor dependency that sends the email. public interface ...
0 votes
2 answers
417 views
Best practice to create nested objects
I always have the same question when I must to work with nested objects structure. An example: class Criteria { filters: Filter[]; } class Filter { field: string; operator: Operator; value: ...