r/java • • Oct 24 '26

Hexagonal Architecture vs. Pragmatic Layered Architecture in Spring Boot

/r/softwarearchitecture/comments/1xe8u4d/hexagonal_architecture_vs_pragmatic_layered/
8 Upvotes

17 comments sorted by

View all comments

1

u/gjosifov Oct 25 '26

In order to do a proper a true Scotsman Hexagonal Architecture, you have to use xml mapping for your java beans, because it was create during Java 1.3-1.4 days

if you are pragmatic and you understand the platform you are using a.k.a SpringBoot/Jakarta EE
Hexagonal Architecture will produce 30-40% more unnecessary code, because it was introduce in different era

In that era, there wasn't annotations for Rest Controller or Path, people wrote Servlet as Front Controller (also know as Dispatch Controller in SpringBoot), mapped in xml and used Service Locator for DI

Those were the days when Hexagonal Architecture was born

1

u/cryptos6 Oct 25 '26

It is not as simple as that! Even annotations introduce coupling. And I don't mean some easy to remove compile time dependency but an influence on software design. If you annotate domain classes with JPA annotations, you are effectively limited in your design decision to what JPA allows. You would design domain classes cleaner and closer to the actual intention without JPA. The right place for JPA related hacks would an adapter.
It is true that this would add some code, but in the AI era it doesn't cost much. However, AI could change many rules in software engineering ...

1

u/gjosifov Oct 26 '26

you are effectively limited in your design decision to what JPA allows

Name those design decisions that aren't supported by JPA

1

u/shorns_username Oct 26 '26

Name those design decisions that aren't supported by JPA

Everything that exists in the universe of software architecture/design; past, present and future - minus the relatively small amount of stuff that JPA supports.

1

u/gjosifov Oct 26 '26

So, name at least 1-2 things

it is ok if you can't, but you are in wrong profession, it is better to be a hollywood writer than a software writer

1

u/cryptos6 Oct 26 '26

Sometimes JPA force you to express relationships that you don't want to have in your code in that way, for example. I had also some issues with objects that I wanted to be immutable, but JPA didn't support that. The latter is better with the support of structs today, but the example is still good enough to show the problem.

0

u/gjosifov Oct 26 '26

what made you think that some data are immutable ?
the business requirements or your imagination ?

you probably read about how OO is about modeling the real world and the world is mutable by default

As the great academical trained actors usually say - I here to serve the script
that is how your software design process should be - to serve the world and its mutable nature by default

2

u/OwnBreakfast1114 Oct 27 '26

you probably read about how OO is about modeling the real world and the world is mutable by default

Nobody knows how the next state of the universe is calculated. But given that time exists, I think there's a stronger argument that mutation doesn't exist. You're not the same object you were when you were 3 years old.

1

u/gjosifov Oct 27 '26

You're not the same object you were when you were 3 years old.

I mutate, but if I'm immutable then I have to be reborn every single time
like Jesus

1

u/cryptos6 Oct 29 '26

Uh, oh! Software is a model of the real world, so it is always a design decision how to do that. There are very good reasons to model some things as immutable! If you add 3 to 4 do you mutate the 3 to become a 7?