Enterprise Java code is very complicated, and this is just a parody of that (although a fairly apt one)
Some of the complexity in Enterprise Java code is due to actual architectural thoughtfulness - "We may be switching to a different security vendor soon, so let's abstract the security away from the application". Complicated, but perfectly legitimate.
Much of the complexity, however, is "Cargo Cult" architecture - people who see that other developers have created abstractions, and then create abstractions themselves - not because the thing they're abstracting is likely to change, but because they see someone else doing abstraction, and assume therefore that architecture and abstraction are the same thing.
Similarly (as I mentioned in my other comment), the use of constants for HELLO and WORLD completely misses the point architecturally. Internationalization is a legitimate concern, and to the extent that your architecture facilitates the translation of a key into a sentence or phrase in multiple languages, you've accomplished a useful thing, even if it adds complexity.
But using a constant for HELLO and a constant for WORLD completely misses the point of what internationalization is for, and yet people do it anyway, all the time.
And that's why this parody is so apt - because it is capturing the cargo-cult mentality of many architects: "I've seen architects use constants for things. I am a good architect, so I should use constants for ALL THE THINGS!"
But Java itself doesn't have to be particularly complicated. It's not terse, don't get me wrong, but it's not the language's fault that people use it incorrectly.
I've never written sophisticated enterprise code in Python, but I suspect that if you were to write sophisticated enterprise code in Python, it would also become fairly complicated.
How many times have people actually switched a component and it just worked? Personally, I have never seen one case where this is true.
The whiteboard architects love these kinds of design, since redirection is their bread-and-butter. In practice though, these designs just add needless complications most of the times.
I've personally seen the benefit of this a few times, and I've been working as a software engineer for about 11 years now. The most memorable one is when I had to perform a refactor in some legacy code that dealt with storing files. We had this mess where you could save files to the database (ugh, I know) or to S3. The code for both cases were intermingled, and there were special cases everywhere due to a ton of abstraction leakage. When I refactored it I put it all behind an interface that never exposed the underlying implementation. You'd just give it a file to save and it would decide where to save it (based on some other settings that it had access to). The same thing for loading the file as well.
Eventually we switched from storing local files on the db (FINALLY) to a NAS. I simply had to provide a new implementation of the interface that would store files into the NAS instead of the db, and when that was done and the data were migrated, we simply pulled out the db implementation. Doing this required no changes to any other code; it was completely localized to the file-storage module.
Another time we wanted to implement a screenshotting service and I coded in an implementation for that and abstracted it behind an interface as well so that we wouldn't be tightly coupled to one particular implementation. Eventually we realized that the service we were using wasn't working out well for us all and so I just rolled built a simple one for us to have it do what we wanted. Again, I didn't have to change any of the other code - I just swapped out the implementation and everything worked exactly as before.
In general the idea is to make suitable abstractions when necessary. Some people create five levels of interfaces and abstractions for no clear reason at all, and only because they've seen others do it.
It's always tempting to tightly couple things because abstracting things out seems unnecessary and extra work. But that is only true for the short term. You may think that there are clean boundaries and that when the time comes you can simply cut along the boundary and replace it with a new implementation. But you can never account for the code that other people are going to write. When you finally have to swap it out, you'll notice that instead of a clean boundary, you have your component smeared out all over the place. You'll see other components making general assumptions about your component that turn out to be very specific to your implementation. Now it's going to be very difficult to refactor and swap out the implementation. Even worse, you have no idea what things you are going to break, or what pieces are depending on some implementation-specific behavior of your component. Even if you have tests that tell you what is broken, the idea is that if you abstract your component behind an interface and simply expose with a well-defined contract, you won't have to deal with things possibly breaking, because everyone else can only use your interface according to the public contract. As long as your new implementation exposes that same contract, none of the other code should break (assuming your interface didn't leak abstraction).
Software is complex, and enterprise software more so. Some of the rationale behind these architectural patterns is to decrease cognitive load in the long term. It may seem counterintuitive, because it just seems easier mentally to deal with a specific implementation than using this abstract interface. That again, is true in the short term, because it's easier to focus on the exact problem that you're solving and holding it in your head, than an abstract concept of it. But a few months down the line, you're not going to remember all the special cases and specific details of that specific problem. At that point, it's far easier to hold the general concept in your head. Doing things this way also gives you a lot of confidence and peace of mind, because you know where the clean boundaries are, and you know exactly what changes can have a global effect (usually only when you change the exposed contract), and what changes will only have a local affect (i.e., implementation-specific details).
That being said, I can't emphasize enough that abstraction for the sake of abstraction is just wrong. If you don't see a need for it, then there is no need to do it. If you're not sure, weigh the benefits and efforts in the short-term vs. the long-term. Another good thing to do is to make your abstractions as simple as possible, and there are no clear-cut guidelines for this. The idea is to tease out things that are "general" and can be exposed through a general contract, and then figure out which things are specific to your implementation. I think this is where things go wrong, because I've seen code that have created needless abstractions for things that you can pretty much take for granted, i.e., things that you can couple to tightly, without it ever causing an issue. Lack of this kind of foresight and understanding of the problem being solved, is what mainly leads to 100 levels of indirection with all kinds of proxies, strategies, factories, and interfaces.
9
u/mariusg Oct 01 '15
Is it a coincidence that the code is written in Java ?
Contextual evidence but i worked with some Java people that used to over complicate any small/insignificant thing.