I have been writing software for many years and have always tried to create expressive, understandable, user-friendly, reliable code. I recently joined a team developing web applications using Spring managed objects. But I am very uncomfortable with this technology. For me, it seems that all the principles of encapsulation and information hiding, the achievements of decades of software development were simply abandoned. I clearly see the advantages of using the Inversion of Control container to move system dependencies from program code to configuration files. But now I see that Spring is used in such a way that, I believe, just adds unnecessary complexity without any benefit.
Using Spring to create support for webapp beans, objects will no longer be clearly organized in modules and will no longer have the highest possible visibility. Instead, there is now one global bean namespace. Because of this, objects tend to get terrible names such as "pendingOrderCustomerName", and to make matters worse, such names do not even clearly identify a clearly defined object, because bean definitions can come from various definition sources collected from explicitly defined locations: instead of just being defined by the class in the package, Spring beans are assembled from xml files with free overriding capabilities and weakly defined relationships.
For example, when I have the type "Account" in simple Java, in the package "my.webstore", I usually know about the properties, relationships and features of this type in one place, "my / webstore" /Account.java ". Instances "Accounts" exist as links to objects that work with accounts, the state of any instance is precisely determined by the class. However, things are complicated with Spring beans: the "Account" instance now exists under a global name in the container management area, which has state collected from xml files found by file search path based on naming templates ...
Gone are the days when, in order to understand what an object does and how it behaves, you just had to read its source program. Today you need a java source object (which can be quite complicated to understand), plus you have to find any configuration files that can change this object, which is not so simple, because you need to find out all the ways from which the configuration can arise need to figure out in which order they redefine each other
Maybe this is just a matter of taste, but I also wonder why people prefer the detailed, clumsy xml syntax, as in:
<bean id="p1" class="Point" scope="prototype"> <property name="x"> <value>20</value> </property> <property name="y"> <value>80</value> </property> </bean>
above this:
p1 = new Point(20,80);
This example may seem exaggerated, but I tell you that I have seen worse!
I do not intend to criticize the Spring framework by itself; it is very strong and is an excellent ingredient in many cases. My problems relate to how to prevent misuse, how to maintain maintainability, how to guarantee quality and stability, how to find dependencies, how to document code ... what is your experience?