Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [design-principles]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
6 votes
2 answers
2k views

How to implement many-to-many relationships without violating design principles in OOP?

I have an event class that holds details of a volunteering "Event" class. There is an "EXCO" Class that can create and edit details of said Events. There is also a "Volunteer ...
bugger's user avatar
  • 79
4 votes
2 answers
954 views

Passing data through events to adhere to the Tell-Don't-Ask principle?

In my little WinForm app, intended to practice as a hobbyist, I'm using this code to pass data from the View to its Presenter: public event Action<object, string, string?>? SearchInAlbums; ...
Valmont's user avatar
  • 183
1 vote
2 answers
204 views

The dependence of the implementation of one class on the implementation of another class

I need to implement a set of algorithms for data processing. Algorithms do not directly access data, but use a set of basic operations that are placed in a separate class. The following code can be ...
Alexey Ismagilov's user avatar
0 votes
1 answer
324 views

Stable abstraction principle

I'm studying design principles, and I have a doubt in package coupling principles. I know that the 'Stable Abstraction Principle' says that a package should be as abstract as stable, and it says that ...
Gius's user avatar
  • 19
0 votes
1 answer
560 views

Source of "... against the interface, not the implementation"

For a paper I am writing, I need to find the origin of the following two phrases: Code against the interface, not the implementation and Test the interface, not the implementation (Note: the ...
Mike Nakis's user avatar
  • 32.2k
1 vote
2 answers
98 views

How to improve the design of the code using tools (e.g. git)?

There is a bunch of books that state principles about good code (SOLID, DRY, Design patterns etc.) Those principles are solutions to some problems. An application of those principles could go like ...
SomeThoughts's user avatar
0 votes
0 answers
101 views

What is the best way to share data between two loosely coupled interfaces?

I have two interfaces: Camera and Computer. So far, each interfaces have multiple implementations in my codebase and they are loosely coupled (no implementations of Camera depends on any ...
Tinker's user avatar
  • 155
-1 votes
2 answers
269 views

Enum and Programming to Interface and best practices

I am learning stuff and have made 2 microservices, Listener and MyApp. Listener is a jms listener (consumer of messages) and MyApp is the app sending messages to queue. I have 2 type of events CREATE ...
Akash Sharma's user avatar
-1 votes
1 answer
228 views

Is "Inheritance as Specialization" hurt? And how can it be fixed? [closed]

Given is the following package/class diagram of an implementation of java.util.List: 1. Which design principle is (most likely) hurt by the ArrayBasedList class? The design principle that is hurt by ...
Konstantinos Loizas's user avatar
-2 votes
1 answer
64 views

How do you enforce API contracts across mutliple stacks?

For systems that are built on top of diverse tech stacks, including both static and dynamic types languages, what is in practice some ways to have the API contracts published and enforced? Some wiki ...
Jim's user avatar
  • 327
2 votes
4 answers
266 views

Altering the state of a composed class by its composing classes. Is there any rule or principle for not doing so?

In other words, is it good to define the method that removes an element in a collection inside the class representing the element, considering a composition relationship? Something like: listElement....
Darius's user avatar
  • 47
-2 votes
1 answer
61 views

Using a field, variable, or column for multiple purposes

I am in a situation right now where a solution has been proposed that uses a csv file. The proposed file structure essentially contains three atomic values; ID Thing 1 Thing 2 Fine. As we were ...
mbcdev's user avatar
  • 9
1 vote
1 answer
452 views

Include Get Password function in User Domain without violating separation of concerns

Problem: I am using a Domain Driven Design architecture and I have a domain model called User as follows: public class User{ public User(string username){ this.Username = username; } ...
Ricardo Duran's user avatar
16 votes
3 answers
8k views

What is separation between policy and mechanism?

The Wikipedia article on separation of mechanism and policy says The separation of mechanism and policy is a design principle in computer science. It states that mechanisms (those parts of a system ...
Tim's user avatar
  • 5,475
15 votes
3 answers
3k views

Is there a conflict between YAGNI and SRP?

I my job, I am tasked with the responsibility of improving the code quality. To meet this responsibility I often pair program with developers and conduct sessions on design principles and design ...
Nachiappan Kumarappan's user avatar
3 votes
3 answers
6k views

How can I implement maker-checker principle?

I am looking into ways for implementing maker checker principle for various classes over our company repository. Basically the rules are as follows: An entity is an object to be seen on a website (e....
Hasan Can Saral's user avatar
3 votes
3 answers
265 views

Injecting only the minimum required into a constructor or function - is there common terminology for this principle?

Probably best explained with an example: In a .NET C# project, we have a library class for which several function accept an HttpContext as one of the arguments. The thing is, that none of the ...
gbro3n's user avatar
  • 491
2 votes
3 answers
2k views

Shifting from Anemic Domain Model to Rich Domain Model

I did a couple of simple projects following Anemic Domain Model . Now I am trying to do the similar type of projects in Rich Domain Model. But I am confused in implementations. Previously , I used to ...
Dot Net developer's user avatar
2 votes
1 answer
139 views

How to write a class that uses other classes but needs the same functionality - should I just wrap around the methods?

I want to create a class ProcessHandler for Windows that pretty much uses the WINAPI. The class ProcessHandler should be able to scan memory, emulate keyboard and mouse, needs some DLLInjector, some ...
Ojav's user avatar
  • 131
2 votes
3 answers
707 views

Is it sometimes okay to intentionally violate the Dependency Inversion Principle?

I am doing some work to refactor a class. It currently a 'God class' and contains all different logic/operations solely in that class. One of my solutions is to extract all different parts of logic to ...
bob9123's user avatar
  • 129
3 votes
3 answers
5k views

Are there any well known alternatives to the SOLID principles for OO programming? [closed]

I´m looking for some kind of better compilation of principles which takes the old basic concepts (DRY, KISS, etc...) and applies them to OOP related concepts like abstract clasess, interfaces etc... ...
jacmkno's user avatar
  • 163
1 vote
1 answer
305 views

What are the potential dangers of using this kind of reflection cheat in Python?

In a program I'm working on, I need to do a substantial amount of real-time reflection in order to maintain a list of known "attributes" throughout the program structure (for use by a sort of "virtual ...
user3002473's user avatar
2 votes
1 answer
454 views

Is it efficient and a normal practice to have one class with thousands of lines of code? [duplicate]

I am currently in a continuous software product development project on base of legacy Java code. The source code is very complicated, which is good and bad. But I am surprised to see that in the core ...
Rui's user avatar
  • 1,699
0 votes
2 answers
131 views

Is there a coding style principle for making class usage consistent

I get to review code that often looks like this: class MyClass1 { constructor MyClass(initialiseParam1: Object) { // do something with initialiseParam1 } initialiseStep2() { ...
eddyP23's user avatar
  • 199
0 votes
2 answers
510 views

The Principle of Allowing One Way to accomplish a Task

What is the official name of the principle, in language design, where the language tries to offer one way of accomplishing a particular task (as opposed to have multiple ways of accomplishing the ...
Lonnie Best's user avatar
1 vote
3 answers
122 views

POLA, Constructor and Getters

As a followup to this question and one I asked a while ago, suppose if I had an Author class structured like this: class Book { private String title; private Set<Author> authorsSet; ...
user avatar
1 vote
1 answer
155 views

Abstract base class implementing an interface, providing a different one to its subclasses

Let's say I have an interface for the Command pattern with undo functionality: interface ICommand { void Execute(); void Undo(); } This comes with a contract. Basically the command can be in ...
Neme's user avatar
  • 121
3 votes
2 answers
1k views

When to keep behaviour inside the domain object vs inside a service object?

So far I put functions into objects, if those functions work exclusively on the object's variables/state. Basically I'm following a non-anemic/rich domain model approach. However, it becomes more ...
teddyD's user avatar
  • 39
4 votes
2 answers
488 views

What algo/design pattern do i need to keep limited time series data constantly updated?

I'm a hobbyist coder; never worked professionally. I am not looking for anyone to write code for me, but I need to know how to approach this problem and, perhaps, ideas for further research. This ...
LeeRoy's user avatar
  • 49
1 vote
5 answers
428 views

Dedicated method vs method with parameter

Suppose we've a permissionManager which tell us if user has some privileges to some action or not. We've quite a lot of them(dozen, maybe more). I see two ways to implement checks for a user, like a: ...
Oleg Kovalov's user avatar
4 votes
1 answer
920 views

Should the presentation layer use domain objects returned from the service layer?

As an example, if there is a controller that calls a CountryService class and the CountryService class uses a Countries class, should the CountryService return the CountriesClass to the controller? Or ...
user3000391's user avatar
1 vote
3 answers
536 views

In interface-segregation principle (ISP) terms, what is meant by depending on unused methods?

The interface-segregation principle (ISP) states that no client should be forced to depend on methods it does not use. My question is: how exactly can a client depend on something that it does not ...
Narek's user avatar
  • 1,143
4 votes
1 answer
610 views

Principle of least privilege vs Interface segregation principle

What is the difference of Principle of least privilege and Interface segregation principle? As much as I understand ISP is just the projection of PoLP on the OOD plain.
Narek's user avatar
  • 1,143
3 votes
3 answers
494 views

How to "program to an interface"

I've read these questions: Understanding "programming to an interface" What is the point of an interface? Does it always make sense to "program to an interface" in Java? I don't ...
rink.attendant.6's user avatar
9 votes
5 answers
1k views

Are there any significant disadvantages to depending upon abstractions?

I was reading this wiki on the Stable Abstractions Principle (SAP). The SAP states that the more stable a package the more abstract it should be. This implies that if a package is less stable (more ...
SteveCallender's user avatar
1 vote
0 answers
91 views

clone(serialize) v. serialize(clone)

My objects serialize() method is dependent on a call to its clone() method, because of its options to get rid of unwanted data without changing the original instance: serialize: function(opt_filters) ...
bebbi's user avatar
  • 361
3 votes
1 answer
265 views

How do you keep up with 'requiring new methods in an interface' (Following LSP and adding new methods to interface seems to violate ISP)

I have a game that deals with opening and closing doors and the Door Engine deals with IDoor interface which has Open() and Close() contracts So far so good. the game is tested and works fine. Now a ...
user136627's user avatar
4 votes
1 answer
223 views

Where to initialize objects

I have an BallEntity class that is part of a game that uses a Entity Component System architecture. This class have 'components' that are like the attributes of that class. I create and initialize ...
alexpfx's user avatar
  • 303
2 votes
1 answer
2k views

Is a class representing a JSON response a DTO, a domain object, or something else?

Consider a restful service in Spring MVC. I am wondering how to package my response classes, i.e. how to name the containing package. First I thought of them as being domain objects. But they are ...
dsplynm's user avatar
  • 143
10 votes
2 answers
6k views

Difference between Single Source Of Truth and Single Responsibility Principle?

So I just found out about the term single source of truth while watching video series about programming code interviews. From what I understood it meant that the single source of truth is an ...
AvetisCodes's user avatar
  • 1,534
0 votes
1 answer
63 views

SOC and self-initializing configuration

Disclaimer: I'm using C# for code examples. But I guess they should be readable/understandable for everyone. If they are not: please leave a comment. Okay I have a Client-Server application. The ...
Brettetete's user avatar
3 votes
4 answers
834 views

YAGNI principle put to practice

I recently came across to this principle and so far it is clear the fact that doing things that you don't need at the moment is not feasible as they might not be used or might be changed. That being ...
Christopher Francisco's user avatar
1 vote
4 answers
1k views

try/catch open/closed principle violation

I have three or more different custom exceptions that a class can throw and I need to use try/catch in order to discover which exception was thrown. In my point of view this piece of code violates ...
yayuj's user avatar
  • 119
2 votes
1 answer
428 views

Tell, Don't Ask and Immutability in a non-directional network

I'm working on a small project in which I'm attempting to practice relatively strict adherence to two ideas: Tell, don't ask (TDA) Immutability The main concept in this project is a Map (as in a ...
Ben Aaronson's user avatar
  • 6,953
1 vote
2 answers
181 views

Define fields only once

I'm looking for a method to describe fields in a structured way, so I am able to reuse it in various languages and levels of my application. For instance, if I'm developing an Android application ...
Stefan Broeder's user avatar
0 votes
1 answer
295 views

Technical example of modeling a domain with OOD?

Considering favoring composition over inheritance and looking at various design patterns there are multiple approaches to modeling a domain. Say you have some Entities which are very similar in some ...
lko's user avatar
  • 387
0 votes
2 answers
101 views

putting methods in base class that doesnt make sense/belong there [closed]

I've been lately thinking over design principles and patterns and a question did strike me. Let us say, I want to design a racing game. I want to design the classes for a variety of cars. each car ...
user136627's user avatar
14 votes
2 answers
5k views

Dependency Inversion Principle: Understanding how both low level components and high level components depend on abstractions

I'm learning about the Dependency Inversion Principle. It states that: High level modules should not depend upon low-level modules. Both should depend upon abstractions. For a while I tried to ...
Aviv Cohn's user avatar
  • 21.4k
3 votes
3 answers
2k views

Implementing the Interface Segregation Principle

Does this IConvertible interface satisfy the Interface Segregation Principle (ie. the "I" in SOLID)? Here is the definition: public interface IConvertible { TypeCode GetTypeCode(); bool ...
Jacob's user avatar
  • 141
2 votes
1 answer
390 views

Single Responsibility Principle and higher levels of abstraction

Two common phrasings for the Single Responsibility Principle (SRP) are "each module should be responsible for a single feature or functionality in a system", and "each module should have only one ...
rick's user avatar
  • 1,975