this post was submitted on 03 Nov 2025
111 points (96.6% liked)

Programming

23348 readers
278 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS
 

As a Java engineer in the web development industry for several years now, having heard multiple times that X is good because of SOLID principles or Y is bad because it breaks SOLID principles, and having to memorize the "good" ways to do everything before an interview etc, I find it harder and harder to do when I really start to dive into the real reason I'm doing something in a particular way.

One example is creating an interface for every goddamn class I make because of "loose coupling" when in reality none of these classes are ever going to have an alternative implementation.

Also the more I get into languages like Rust, the more these doubts are increasing and leading me to believe that most of it is just dogma that has gone far beyond its initial motivations and goals and is now just a mindless OOP circlejerk.

There are definitely occasions when these principles do make sense, especially in an OOP environment, and they can also make some design patterns really satisfying and easy.

What are your opinions on this?

(page 2) 42 comments
sorted by: hot top controversial new old
[–] melfie@lemy.lol 10 points 1 day ago* (last edited 1 day ago)

Like anything else, it can be useful in the right context if not followed too dogmatically, and instead is used when there is a tangible benefit.

For example, I nearly always dependency inject dependencies with I/O because I can then inject test doubles with no I/O for fast and stable integration tests. Sometimes, this also improves re-usability, and for example, a client for one vendor’s API can be substituted with another, but this benefit doesn’t materialize that often. I rarely dependency inject dependencies with no side-effects because it’s rare that any tangible benefit materializes, and everyone deals with the additional complexity for years with no reason. With just I/O dependencies, I’ve generally found no need for a DI container in most codebases, but codebases that dependency inject everything make a DI container basically mandatory, and its usually extra overhead for nothing, IMO. There may be codebases where dependency injecting everything makes perfect sense, but I haven’t found one yet.

[–] masterspace@lemmy.ca 11 points 1 day ago* (last edited 1 day ago)

The SOLID principles are just that principles, not rules.

As someone else said, you should always write your code to be maintainable first and foremost, and extra code is extra maintenance work, so should only really be done when necessary. Don't write an abstract interface unless multiple things actually need to implement it, and don't refactor common logic until you've repeated it ~3 times.

The DRY principle is probably the most overused one because engineers default to thinking that less code = less work and it's a fun logic puzzle to figure out common logic and abstract it, but the reality is that many of these abstractions in reality create more coupling and make your code less readable. Dan Abramov (creator of React) has a really good presentation on it that's worth watching in its entirety.

But I will say that sometimes these irritations are truly just language issues at the end of the day. Java was written in an era where the object oriented paradigm was king, whereas these days functional programming is often described as what OO programming looks like if you actually follow all the SOLID principles and Java still isn't a first class functional language and probably never will be because it has to maintain backwards compatibility. This is partly why more modern Java compatible languages like Kotlin were created.

A language like C# on the other hand is more flexible since it's designed to be cross paradigm and support first class functions and objects, and a language like JavaScript is so flexible that it has evolved and changed to suit whatever is needed of it.

Flexibility comes with a bit of a cost, but I think a lot of corporate engineers are over fearful of new things and change and don't properly value the hidden costs of rigidity. To give it a structural engineering analogy: a rigid tree will snap in the wind, a flexible tree will bend.

[–] Windex007@lemmy.world 8 points 1 day ago (2 children)

Whoever is demanding every class be an implementation of an interface started thier career in C#, guaranteed.

load more comments (2 replies)
[–] aev_software@programming.dev 10 points 1 day ago (1 children)

The main lie about these principles is that they would lead to less maintenance work.

But go ahead and change your database model. Add a field. Then add support for it to your program's code base. Let's see how many parts you need to change of your well-architected enterprise-grade software solution.

[–] justOnePersistentKbinPlease@fedia.io 7 points 1 day ago (2 children)

Sure, it might be a lot of places, it might not(well designed microservice arch says hi.)

What proper OOP design does is to make the changes required to be predictable and easily documented. Which in turn can make a many step process faster.

[–] davidagain@lemmy.world 2 points 1 day ago

I have a hard time believing that microservices can possibly be a well designed architecture.

We take a hard problem like architecture and communication and add to it networking, latency, potential calling protocol inconsistency, encoding and decoding (with more potential inconsistency), race conditions, nondeterminacy and more.

And what do I get in return? json everywhere? Subteams that don't feel the need to talk to each other? No one ever thinks about architecture ever again?

I don't see the appeal.

[–] aev_software@programming.dev 3 points 1 day ago (2 children)

I guess it's possible I've been doing OOP wrong for the past 30 years, knowing someone like you has experienced code bases that uphold that promise.

[–] calliope@retrolemmy.com 6 points 1 day ago* (last edited 1 day ago)

Right, knowing when to apply the principles is the thing that comes with experience.

If you’ve literally never seen the benefits of abstraction doing OOP for thirty years, I’m not sure what to tell you. Maybe you’ve just been implementing boilerplate on short-term projects.

I’ve definitely seen lots of benefits from some of the SOLID principles over the same time period, but I was using what I needed when I needed it, not implementing enterprise boilerplate blindly.

I admit this is harder with Java because the “EE” comes with it but no one is forcing you to make sure your DataAccessObject inherits from a class that follows a defined interface.

We all have or own experiences.

Mine is that it helps in organization, which makes changes easier.

[–] davidagain@lemmy.world 3 points 1 day ago

The promise of oop is that if you thread your spaghetti through your meatballs and baste them in bolgnaise sauce before you cook them, it's much simpler and nothing ever gets tangled up, so that when you come to reheat the frozen dish a month later it's very easy to swap out a meatball for a different one.

It absolutely does not even remotely live up to it's promise, and if it did, no one in their right mind would be recommending an abstract singleton factory, and there wouldn't be quite so many shelves of books about how to do oop well.

[–] ravachol@lemmy.world 8 points 1 day ago

My opinion is that you are right. I switched to C from an OOP and C# background, and it has made me a happier person.

[–] gezero@lemmy.bowyerhub.uk 4 points 1 day ago* (last edited 1 day ago)

If you are creating interfaces for classes that will not have second implementation, that sounds suspicious, what kind of classes are you abstracting? Are those classes representing data? I think I would be against creating interfaces for data classes, I would use records and interfaces only in rare circumstances. Are you complaining about abstracting classes with logic, as in services/controllers? Are you creating tests for those? Are you mocking external dependencies for your tests? Because mocks could also be considered different implementations for your abstractions. Some projects I saw definitely had taken SOLID principles and made them SOLID laws... Sometimes it's an overzealous architect, sometimes it's a long-lasting project with no original devs left... The fact that you are thinking about it already puts you in front of many others...

SOLID principles are principles for Object Oriented programming so as others pointed out, more functional programming might give you a way out.

[–] Jankatarch@lemmy.world 1 points 1 day ago* (last edited 1 day ago)

What's wrong with making a public static singleton class "isEven" and inheriting it to accomplish your goal class, "isOdd."

[–] alexc@lemmy.world 3 points 1 day ago (1 children)

SOLID is generally speaking a good idea. In practice, you have to know when to apply it.

it sounds like your main beef in Java is the need to create interfaces for every class. This is almost certainly over-engineering it, especially if you are not using dependency inversion. IMHO, that is the main point of SOLID. For the most part your inversions need interfaces, and that allows you create simple, performant unit tests.

You also mention OOP - It has it’s place, but I would also suggest you look at functional programming, too. IMHO, OOP should be used sparingly as it creates it’s own form of coupling - especially if you use “Base” classes to share functionality. Such classes should usually be approached using Composition. Put this another way, in a mature project, if you have to add a feature and cannot do this without reusing a large portion of the existing code without modifications you have a code-smell.

To give you an example, I joined a company about a year ago that coded they way you are describing. Since I joined, we’ve been able to move towards a more functional approach. Our code is now significantly smaller, has gone from about 2% to 60% unit testable and our velocity is way faster. I’d also suggest that for most companies, this is what they want not what they currently have. There are far too many legacy projects out there.

So, yes - I very much agree with SOLID but like anything it’s a guideline. My suggestion is learn how to refactor towards more functional patterns.

[–] aev_software@programming.dev 5 points 1 day ago (1 children)

In my experience, when applying functional programming to a language like java, one winds up creating more interfaces and their necessary boilerplate - not less.

[–] alexc@lemmy.world 2 points 1 day ago

True… I personally dislike Java and work mostly in Kotlin these days.

[–] brian@programming.dev 1 points 1 day ago

most things should have an alternate implementation, just in the unit tests. imo that's the main justification for most of SOLID.

but also I've noticed that being explicit about your interfaces does produce better thought out code. if you program to an interface and limit your assumptions about implementation, you'll end up with easier to reason about code.

the other chunk is consistency is the most important thing in a large codebase. some of these rules are followed too closely in areas, but if I'm working my way through an unfamiliar area of the code, I can assume that it is structured based on the corporate conventions.

I'm not really an oop guy, but in an oop language I write pretty standard SOLID style code. in rust a lot of idiomatic code does follow SOLID, but the patterns are different. writing traits for everything instead of interfaces isn't any different but is pretty common

[–] ozymandias@lemmy.dbzer0.com -3 points 1 day ago

java is garbage

load more comments
view more: ‹ prev next ›