Questions tagged [solid-principles]

SOLID is an acronym for five principles of object-oriented design introduced or documented by Robert C. Martin. Use this tag on questions regarding any of the individual principles, or their relationships to other OOD concepts. Also use the five individual tags, when applicable.

The SOLID principles are language-agnostic principles of object-oriented design. (Not to be confused with tools and conventions for decentralized social applications proposed by Tim Berners-Lee and MIT.) In a series of articles in 1996, Robert C. Martin documented the existing Open-Closed and Liskov Substitution principles, and introduced the other three. Michael Feathers invented the acronym afterwards.

The acronym stands for:

References:

1149 questions
-1
votes
1 answer

Solid principal violation

The following code violates Solid principal, does anybody know how should I refactor it? I couldn't find any solution to refactoring this code to follow solid principals. public class Calculator { public int Calculate(int a, int b, string…
Jafar ashrafi
  • 511
  • 6
  • 18
-1
votes
1 answer

PHP OOP Factory pattern and Open/Closed principle

I would like to implements PHP notifications system with PHP OOP. I have many notifications type and each notification will do custom work and checks user settings before showing notification to users. I add Notification abstract class to fix…
Gaddour Mohamed
  • 119
  • 2
  • 9
-1
votes
1 answer

How can I make this small pseudocode comply with Liskov principle?

Keeping things tidy and simple, here is my initial Java pseudocode as an example: public abstract class Vehicle { private String owner; private id plate; public removeVehicle() { if (typeof(this) == Car)…
-1
votes
1 answer

In open close principle, what exactly is modification and extension?

Ok, so I know the obvious example of modification, that is when we need to modify an existing behaviour to add a new one. But, when we just need to add code that doesn't change anything but just add new functionality, does this count as modification…
vacih86456
  • 237
  • 1
  • 7
-1
votes
1 answer

How to design hardware interfaces in C# while staying DRY and SOLID?

I am having a design problem with an application that handles two or more networked I/O devices. Both devices share properties like a name, IP address, and port. They will also share methods such as Connect(), Disconnect(), IsConnected(). In an…
oSiv
  • 26
  • 4
-1
votes
2 answers

About interface and extension

Suppose I have an interface A with method a, and B is a concrete class which implements A. public interface A { public void a(); } public class B implements A { public void a() { // implementation } } Now suppose there is a…
once
  • 536
  • 7
  • 21
-1
votes
2 answers

What are the best practices for accessing android resources from ViewModel?

I am working my way into the clean-code-pattern and came across the following question to which I unfortunately did not find an answer: What is the best solution to access android resources from the ViewModel, like strings, colors, etc. Maybe I just…
Thomas Cirksena
  • 717
  • 2
  • 8
  • 28
-1
votes
1 answer

Code for exporting objects in various formats while reporting progress, making it more extensible

Description A WinForms application has a function to export objects of the following type, in various formats: class Item { public int id { get; set; } public string description { get; set; } } At the click of a button in a window, a…
Al2110
  • 566
  • 9
  • 25
-1
votes
1 answer

Model a date time range object hierarchy

Newbie to code refactoring, I have a simple object as follow public class TimeRange { public Guid Id { get; set; } public DateTime StartTime { get; set; } public DateTime EndTime { get; set; } } public class…
-1
votes
1 answer

how to make function simpler

I tried to follow solid principles and want to make my code better. So I want to separate the function that may not be used in some problems. this is the code that I already to separate but still redundant private lateinit var dialogView : View …
Qube
  • 543
  • 3
  • 9
  • 23
-1
votes
1 answer

The properly OOP approach in operation of lists?

I have an OOP question, for example, there are lists (arrays). Needed a mechanism that will add (save) and delete the selected values ​​from each array. The output should be for each array of its selected elements. The logic of adding can be…
user13763587
-1
votes
2 answers

3 Layers architecture in vending machine, while keeping OCP

I'm working on a vending machine project, and i tried to split it into UI and BL layers, But I'm getting into problem. For example I have this function for paying in coins, which derives from an abstract class: public override void Pay(decimal…
-1
votes
2 answers

Is it a dependency Injection anti-pattern a base class with many constructors?

I thought about doing a base class to centralize all properties that can be used in the child classes when needed. My question is whether what I'm doing is an dependency Injection anti-pattern. If so, could you give examples of what would be best to…
-1
votes
1 answer

Is this a violation of the Single Responsibility Principle?

I'm reading The Pragmatic Programmer, 20th Anniversary Edition and I'm thinking about whether or not this code snippet violates the Single Responsibility Principle: class Line { private double length; private Point start; private Point end; …
Overflow 404
  • 482
  • 5
  • 20
-1
votes
2 answers

replace if statments with clean code and best practices

It is a simple code, what I am looking for is to learn the best practices that I can implement, when trying to refactor the show method, to a method that is closed to modifications. so that in the future if they ask me to enter a new card with a…