Justin Etheredge is a Senior Consultant for Dominion Digital in Richmond, Virginia - United States. He likes to blog quite a bit at http://www.codethinked.com with hopes that someone out there might read it. When he isn't writing software or working on his computer... wait, he is always doing that. Anyways, Justin likes programming, a lot. Justin has posted 24 posts at DZone. View Full User Profile

The Static Spider Web Pattern

12.23.2009
| 6286 views |
  • submit to reddit

While the developer lexicon is loaded up with more patterns than we can possibly ever learn, I just wanted to introduce one of the more important patterns that I think exists out there in software development. I call it the “Static Spider Web” pattern. The main driver behind this pattern is that object instantiation, allocation, and deallocation impose far too much overhead in modern programming language runtimes. Since we aren't in direct control of memory management, and since garbage collectors on systems with large amounts of memory can cause huge latency overheads, we need to find some way to minimize, at all costs, the number of objects that we allocate.

"I'm picking up your sarcasm." "Well, I should hope so, because I’m laying it on pretty thick." –Tommy Boy

First, we are going to have to just accept the fact that we will have to create a few objects. I mean, our application data needs to go somewhere, right? I'd advocate for passing the data around as parameters, but that would get old pretty quick with all of that typing. Besides, that is what objects were invented for, to be stateless data containers.

Read the rest of this post at http://www.codethinked.com

Published at DZone with permission of its author, Justin Etheredge.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Thomas Eichberger replied on Wed, 2009/12/23 - 6:58am

I would laugh if it wasn't so sad. I think this article shows a valid design pattern for a lot of programmers. Unfortunately.

Andrew Arrigoni replied on Wed, 2009/12/23 - 8:20am

Shut up, man! I was young and inexperienced! *goes to cry in a corner*

Fab Mars replied on Wed, 2009/12/23 - 8:57am

Very smart article where everyone will find food for thought! Congrats.

If you're working in a container and this ones doesn't manage your instanciations, you end up working more or less like what's described above. Even if you're experienced.
The typical example was a Struts app using Hibernate a few years ago. No matter how hard you tried you were forced to "propagate static". 

Then DI arrived and solved a part of the problem. You still had some static "entry points" here and there.
With nowaday's SE/EE and a handful of thoughtful developers, you can avoid that issue :) Not always though.

Dapeng Liu replied on Wed, 2009/12/23 - 10:19am

Good luck ...

Stephane Vaucher replied on Wed, 2009/12/23 - 12:09pm

I started banging my head on my desk when I read the author's comments on object allocation. Then, I saw his comments on static methods, then I nearly passed out. I blacked out when XML came into the mix. When I woke up, I realised the sarcasm. Hopefully, no one will take this article seriously.

Olive Zuo replied on Wed, 2009/12/23 - 1:29pm

Really funny Christmas gift.

Artur Biesiadowski replied on Wed, 2009/12/23 - 4:44pm

Don't worry, this article is about C# (properties, small string, bool instead of boolean, funny IDE). Nobody programs java this way anymore ;)

Rohit Chandramohan replied on Wed, 2009/12/23 - 5:10pm

Looks like a twisted and contorted evil pattern. One you want to stay away from !!! ;-)

Loren Kratzke replied on Wed, 2009/12/23 - 8:37pm

Ship it!

Dapeng Liu replied on Sat, 2009/12/26 - 3:36am

Actually i only see the 'web' where is the 'spider'??

Eran Harel replied on Sat, 2009/12/26 - 4:21am

That's a good one.

I would have laughed if I didn't have to deal with this approach on a daily basis...

It will take us years to refactor your code :P

Markus Spika replied on Sat, 2009/12/26 - 6:39am

I'd totally point at you and laugh if i wouldn't have to cry because of currently maintaining exactly that for a living. :-(

 

Total highlights of this article for myself:

* stateless data containers. (oximornon of the year award!)

* the obligatory class XXXManager

* the obligatory class DataLayer

 * And my personal favorite: everything talking to everything via XML (bonus points if its a self-inventend object/xml mapping)

 

Next time you should give the XXXHelper and XXXUtil classes the attention they deserve.

Escpecially those utility-demigods that can do database queries, data correction, representation preparation and incorporate at least 25% of the businesslogic of every usecase.

 

happy holidays

 

PS.: Isn't this already known as the Cthulhu-Pattern?

Gerrit Jansen V... replied on Sat, 2009/12/26 - 7:43pm

This is so funny I would laugh if it wasn't for the almost heart attack I had when reading this. Good graphics. Then just when I had my injection directly to the heart and came back to life I realised that hey maybe this is a joke and a critisism to what happens in most (commercial)java projects. Sadly most of the comercial java projects I have seen have this pattern or even worse. Testability : How can you possible test a static method???????? If a static method calls another static method calls 20 more static methods that each needs some special services running to deliver x values, how in this world would you unit test that???? With a decent OO design you'll be able to mock this and mock out the methods that need the special services. How in this world would you do this with Java using static methods??? Byte code engineering??? In this world, if you just whant to write a test for a new algorithm for what every sos imple you've written you don't whant to launch special services like Web Service, JNDI service, Open EJB, Tomcat, Jetty, the lot and 2minutes later you'll be able to run your test, so that you can pass the string "222^200:200^122^2200:200" to it and get result 2. this is sad but most java projects are written this way :(, and then java gets the wrap for project failure. On more than one project I've seen its almost better the start from scratch than continue with statics all over the place. Please when we learn about Factory pattern and other static method prone patterns it doesn't mean use static when every you can!!!!....

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.