It’s impossible to write OOP code with Spring. From its core it promotes the use of singletons and anemic data structures a.k.a. data “objects” a.k.a. DTO. This fuels procedural programming and kills OOP.

In the next paragraphs I’ll highlight three **major **Spring components involved. I start from the core.

IoC Container

The core of Spring is the IoC container, represented by the

ApplicationContextinterface. Basically it defines a context through which we get beans. A bean is an object managed by the container and it has a name attached to it.

We can configure the context thanks to some annotations, called steorotype. These annotations were introduced in Spring 2.5 and enhanced in Spring 3.0. Previously we could only use an external XML. This was even worse…

So we annotate a class with a stereotype, the container reads it and it builds a bean. A bean is a singleton. For this reason it cannot represent anything specific. This means that to do something useful we should pass around data “objects” through them.

A bean is an object only from a technological point of view. But at the conceptual level it’s just a namespace for procedures. In other words it’s a bunch of procedure grouped by a name. Nothing more. Every bean, regardless the stereotype, is bad.

This is not OOP. But I’m not saying anything new. It’s known that singleton are bad. But this (anti)pattern is the Spring backbone.

At this point it should suffice to say that everything else in Spring is based on bean. This means that every Spring application is composed by bean that works on data structure. Definitely this is not OOP.

However I think that things gets worse with the next two components…

#spring #spring-boot #java #spring-mvc #spring-data #oop #procedural-programming #software-engineering

Spring Framework: To Use Or Not To Use, That Is The Question
1.30 GEEK