Looking after your domain model

Mats Helander has written an excellent article on how to manage your domain model with some intelligent design trade-offs.  It’s a lengthy article that even manages to introduce AOP as well.  If you start reading it and wonder where it’s going, just carry on reading…it is written in an evolutionary style.  Nice article, Mats! UPDATE: I have written the Java equivalent of the listing in Mats’ article and attached it.  The AOP part uses SpringFramework 2.5 and AspectJ.  

Get Cooking with JRuby on Rails

Some of the companies that I interact claim that they will never switch to Ruby on Rails (or just plain ‘ol Ruby) for that matter. But with JRuby reaching 1.0 status (and currently on 1.0.2 with 1.1b1 already released) this changes the situation somewhat. Now it is possible to develop Rails apps and run it on your Java infrastructure that make use of native JDBC connections and a whole bunch more.

Pre-requisites

Since we want to run a Ruby on Rails app on a Java application server, we need to have a Java web container such as Tomcat, Jetty or Glassfish. In my case, I’ll be dropping the app into into a Glassfish domain. I guess that this should work just fine for Tomcat as well, but I have not verified this as yet.You also need a database and I will be using MySQL. If you are going to use another database, you need to make sure that the ActiveRecord-JDBC adapter has been developed for the DB. ActiveRecord is the ORM for Rails apps. Currently, there are ActiveRecord-JDBC adaptors for HypersonicSQL, Derby, MySQL and PostgreSQL. This is true for version 0.6 of ActiveRecord-JDBC. For other adapters, you will need to specify a proper JDBC URL in your application’s database configuration file, config/database.yml. This will make a lot more sense once you finish this exercise.All of the above (except or ActiveRecord, of course) should be stock standard goodies on any self-respecting Java development box. With this place, let’s get cooking.

Install JRuby

Download the JRuby bin distribution from the JRuby downloads page. At the time of writing this, 1.1b1 has been released. I am currently using the 1.02 release. Unzip/untar the file to somewhere convenient, add an environment variable JRUBY_HOME to point to the extracted directory, and add JRUBY_HOME/bin to your path.

	/> cd ~/tools	/> tar xzvf jruby-bin-1.02.tar.gz
	/> export JRUBY_HOME=~/tools/jruby-1.0.2
	/> export PATH=$PATH:$JRUBY_HOME/bin

You can verify your JRuby installation with:

	/> jruby -v
	ruby 1.8.5 (2007-11-01 rev 4810) [i386-jruby1.0.2]

 You will notice two versions being reported. The first tells us that the ruby implementation is version 1.8.5 and the second tells us that it is running on jruby 1.0.2 on i386 platform. If you are new to ruby, then you need to know that there are different implementations of ruby, with the definitive one called MRI (Matz’s Ruby Implementation – Matz is the original author of ruby). JRuby is an attempt at a complete port of MRI to Java, aiming to eliminate all dependencies on C libraries. This is one of the significant points about JRuby: it is pure Java.

Install RubyGems

The closest Java equivalent of RubyGems is Maven or Ant+Ivy. Gems is a library and dependency management tool for ruby. On a native ruby install, you would have to download and install RubyGems, but JRuby already has RubyGems rolled in. Take a peek at JRUBY_HOME/bin and you should see an executable file called gem. So, nothing more to do here. What the heck, let’s verify that RubyGem is working.

	/> jruby -S gem -v
	0.9.4

If $JRUBY_HOME/bin is first in your path, then you can try /> gem -v. The -S tells jruby to run the command that follows from $JRUBY_HOME.For the ruby folk, you should realize that JRuby has rolled in RubyGems version 0.9.4 which is as fresh as it comes.The closest Java equivalent of RubyGems that I can think of is perhaps Maven or ANT+Ivy. But RubyGems takes the prize hands-down for its absolute simplicity. Install rake and Rails below and see what I mean.

Install Rake

 Rake is a really good build tool for ruby (i.e a make for ruby, hence the goofy name). Once you start writing rake build scripts, you will wonder why one earth you thought ANT is nice. Anyway, let’s install rake.

	/> jruby -S gem install rake

Install Rails

Now that you’ve seen the goodness of RubyGems, install Rails and the ActiveRecord for JDBC.

	/> jruby -S gem install rails -v 1.2.6 -y --no-rdoc --no-ri
	/> jruby -S gem install activerecord-jdbcmysql-adapter --include-dependencies

We are deliberately installing Rails version 1.2.6. Rails 2.0.1 was released in early December 2007 and I have not taken 2.0.1 for a drive under jruby yet. So, we’ll stick to version 1.2.6 which is still great.

Get MySQL Ready

 We’re heading for the home straight with all this setup and configuration nonsense. Just a couple of things to do.

  • Copy the MySQL JDBC driver to $JRUBY_HOME/lib.
  • Create a MySQL database called testapp_development. Rails apps require three databases; one for development (suffixed _development), one for unit testing (suffixed _test and is wiped clean with every test run) and one for production (suffixed _production). For this exercise, we will just use the development database with full rights given to the MySQL user root with no pasword.

Create the Rails App

Now the fun starts! Finally!The next command will create a directory with the same name as your application. So, change to a directory that will contain your rails applications. In my case, I keep my applications in ~/projects/jruby.

	/> cd ~/projects/jruby
	/> jruby -S rails testapp

Now you should have a directory called testapp. Let’s see if our app works. Yes, in rails-land, the app can already be fired up!

	/> cd ~/projects/jruby/testapp
	/> jruby script/server

This fires up webrick, a built in http server with ruby support built in. Just point your browser to http://0.0.0.0:3000 and you should see the Rails happy page. Kill webrick by hitting CTRL+C.

Link up to your database

Edit the file config/database.yml and change it as follows. Note that the line socket: /tmp/mysql.sock must be removed.

	development:
  	  adapter: mysql
  	  database: testapp_development
  	  username: root
  	  password:

and

	production:
  	  adapter: mysql
  	  database: testapp_development
  	  username: root
  	  password:

 YML files are files that store configuration using YAML, which is a ” is a straightforward machine parsable data serialization format designed for human readability”.Now, let us inform the Rails app that we are using ActiveRecord-JDBC. Add the following to the file config/environment.rb just before the line Rails::Initializer.run do |config|.

  if RUBY_PLATFORM =~ /java/
    require 'rubygems'
    RAILS_CONNECTION_ADAPTERS = %w(jdbc)
  end

Create a table (the Rails way)

 Sure, we can write a simple SQL script to create the table we want, but for fun, let’s do it using some Rails sugar. You can keep your app running in webrick and still do the this. Just open up another command or shell, switch to your project directory and get going. This is one of the nicest bits of Rails – you can do most things without a restart of your application server.

	/> jruby script/generate migration AddGadgetsTable

This should have created a file db/migrate/001_add_gadgets_table.rb. Open this file and edit it as follows.

	class AddGadgetsTable < ActiveRecord::Migration
	   def self.up
	      create_table :gadgets do |table|
	         table.column :name,  :string, :null => false
	         table.column :color, :string, :null => false
	      end
	   end
	   def self.down
	      drop_table :gadgets
	   end
	end

After saving the file, run the following command to create the table. Actually, we’re migrating our existing database to version 001! Database refactoring is a definite goal of Rails. It may not be perfect, but it is certainly better than maintaining a bunch of SQL files.

	/> jruby -S rake db:migrate

 Even if you’ve never seen ruby before, the above is certainly readable and you can easily understand that we intend to create a table called gadgets with two columns name and color. Actually, there are more than these two columns. Have a look at the table structure and check that a primary key colum id has been added as well.

Generate Scaffolding to maintain the table

I know, I know, I know! Code generation for anything but the most trivial of code can be dramatic for newbies but real code takes a lot more effort. The point here is just to get some Rails code up and running so that we can deploy it in a Java application server. So, please bear with me.

	/> jruby script/generate scaffold gadget

Fire up webrick and visit the URL http://0.0.0.0:3000/gadgets. You should see a page with an empty list of gadgets and CRUD links.

Get ready to WAR

We need a few additional rake tasks to be able to build a WAR for our Rails application. The Goldspike plugin for Rails does just that. Let’s install the Goldspike plugin.

	/> jruby script/plugin install 
		svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike

All that’s required is to add the WAR dependency on the MySQL driver. What’s great about Goldspike is that we can declare Maven dependencies. Great combination: RubyGems for Ruby-land and Maven for JRuby-land! Open the file vendor/plugins/goldspike/lib/war_config.rb and add the following line to the list of # default java libraries block.

	add_java_library(maven_library ('mysql', 'mysql-connector-java', '5.0.5'))

Build the WAR

Now build the WAR using rake.

	/> jruby -S rake war:standalone:create

If you look in the root of your application directory, there should be a file testapp.war

Drop it into Glassfish

 Start your Glassfish domain, log in to the Glassfish admin console and click the Deploy Web Application link. Browse to the testapp directory and select the testapp.war file. If the app is not enabled, then select testapp, and click Enable.

See it in action

Point your browser to http://localhost:8080/testapp. You should see the Rails happy page, and http://localhost:8080/testapp/gadgets has the CRUD for our Gadget object.As easy as pie! And just as nice!

Treading into OSGi

On my current project, the number of JavaBeans / Spring Beans is becoming a bit too much to handle. What’s becoming quite painful is that there is a significant number of combinations and dependencies between beans, and between the various web applications that we are rolling out. Simply including a few “common” JARs in multiple WAR’s is not good enough anymore.Modularity and dynamic modules has always been painful in Java, mostly due to its ridiculous class loader. But OSGi seems to offer significant improvements in this area.  The possibilities of having classes “plugging” into each other, resolving versions, etc., all dynamically is terribly exciting and, at the same time, frightening.Nevertheless, I will be venturing into OSGi land and will blog my experiences and hopefully provide a some simple HOWTO’s and tutorial style posts.

The optimistic concurrency gotcha

In my current project, I have a group of about 7 budding young developers none of whom have done any significant web development.  This includes hitching up to a database and using object relational mappers.  The one thing that always gets first-timers is stateless nature of the web.  And the first solution they come up with is session based statefulness which eventually leads to a scalability bottleneck.  The ripple effect of lack of state is that you need to have optimistic concurrency at the data access level.  Now most of us just assume that our OR Mapper will solve that for us.  And, yes, they do offer optimistic concurrency out of the box, be it with a version column or without.  But Mats Helander makes a strong point that optimistic concurrency in most (maybe all) OR Mappers actually kicks for really short durations (milliseconds).  In that case, you might as well be using good old fashioned database transactions.  Mats suggests that a way to solve the problem is to store original values in the view.  Check out Mats’ post and you’ll see why you should be storing, at the very least, your Hibernate version column/property on your view as well.

Not everything has to be Object Oriented

For some time now I have been wondering whether we have become completely obsessed with object oriented analysis and design.  Hence my step into the world of functional programming.  This led me first to Haskell and also Erlang. Interestingly, Niclas Nilsson has posted a thought provoking piece on InfoQ which asks whether Erlang is the next Java.  Also, check out the comment on Scala which is now on my radar as well. Maybe functional languages will be the language for Web 3.0 where semantic interoperability and semantic correctness will be prominent.

Kung Fu Coding – Bruce Lee Style

Bruce Lee would have been one awesome software developer. Even better, I would have really loved him being my coach or mentor. I came a across a site with his views on Jeet Kun Do and was astounded by the relevance to agile software development. There’s definitely something in it for everyone involved in a software development effort: from requirements gathering and problem definition, writing code and unit tests, software architecture and mentorship to attitude and values. Check out the following (anything in italics is a Bruce Lee quote) …
On Understanding the Problem or Domain

One the traps we often fall into when facing a problem domain is that of exploding the problem into spaces that we never anticipated. Often we lose track of the original problem. Users are equally guilty of digressing from the problem space. But check out Bruce Lee’s approach:

In building a statue, a sculptor doesn’t keep adding clay to his subject. Actually, he keeps chiselling away at the unessentials until the truth of its creation is revealed without obstructions. Thus, contrary to other styles, being wise in Jeet Kune-Do doesn’t mean adding more; it means to minimize, in other words to hack away the unessential. It is not daily increase but daily decrease; hack away the unessential. 

The key is to remain focused, “to hack away the unessential”, so you can get to the truth – the heart of the problem. Now our stories/use cases and release plans focus directly at the core of the problem. The truth is revealed and the starting point for test driven development is cut to the bone, it’s bare. You know exactly where to start and what you are solving.

Writing Clean Code (without smells)

So we have our problems defined, we have a some cool release plans and we start some early designs. Again, complex solutions ead to complex implementations. In agile software development we always aim for simplicity. This is exactly what Bruce Lee’s Jeet Kun Do is all about.

My movements are simple, direct and non-classical. The extraordinary part of it lies in its simplicity. 

and

One must be free. Instead of complexity of form, there should be simplicity of expression. 

I always coach teams by saying that “If you draw it, you must build it … otherwise don’t draw anything”. The simpler the solution that is architected, the higher the chance of success at the code level, implementation level, maintenance level, all levels. Bruce Lee maintains that “I always believe that the easy way is the right way.”

Avoiding Code Bloat

So we have our bare-bones problem with a simplist solution possible, and we start coding. How often, have you meandered off to explore some cool feature that your user will just love? But it doesn’t address the problem. And test driven development trys to address that. But here’s some very sobering advice from Mr. Lee:

Don’t indulge in any unnecessary, sophisticated moves. You’ll get clobbered if you do, and in a street fight you’ll have your shirt zipped off you. 

From this moment on, the imagery of having my shirt ripped off and getting clobbered is enough to keep me on the right track. At a more basic level, it is the philosophy of suppressing your ego (the “cool” recognition factor) that is so essential in reducing code bloat.

Embracing Change

You crafted your solution, you are about to go live and a new requirement sneaks in. SCOPE CREEP!!! CAN’T DO THAT!!! In Extreme Programming, you are meant to embrace change and react to it in a manner that serves the interests of all stakeholders. However, you can only react if you are flexible, if your design is simple and fluid. Bruce Lee reckons that “One should not respond to circumstance with artificial and ‘wooden’ prearrangement.” If you stick to a rigid point of view, or react rigidly with pre-conceived intent, then that essential new requirement will never see the light of day. Be fluid and react accordingly. If your design is simple and fluid, if your code is simple and fluid, you can embrace the changes.

Use of Tools and Technologies

I often come across teams where the choice of tools, technologies, languages, frameworks, etc becomes an obsession. I have seen far too many architectures where a one-framework/language/tool-will-do approach just kills off an otherwise excellent piece of work. For these situations, remember “Any technique, however worthy and desirable, becomes a disease when the mind is obsessed with it.” There is always a another way to solve a problem, or produce the same result. Don’t become obsessed with your choices. There is nothing wrong with writing core backend code in Java or C# and front end code in Ruby where a dynamic language is, maybe, a better option.Even more appropriate: “Again let me remind you Jeet Kune Do is just a name used, a boat to get one across, and once across it is to be discarded and not to be carried on one’s back.” The way I see it is that once you’ve used something, done some good, there’s no reason to be burdened by it. If your choices have served their purpose then accept that, appreciate it and move on…don’t force the same fit everytime.

Coaching Teams

So you squeezed in the new requirement and you have some happy users. You decide to build your team and be the head-geek … the ARCHITECT guy!! Now your responsibilities change, you have to guide, mentor and help the unenlightented so they too can be fluid. You impose your way on a few newbies, you tell them what patterns they should use and what algorithms where wrong choices. And you have a mutiny. Why? Because, according to Bruce Lee:

Each one of us is different and each one of us should be taught the correct form. By correct form I mean the most useful techniques the person is inclined toward. Find his ability and then develop these techniques. 

I have so often made the mistake of leading people into my way of thinking, my way of coding, my way of writing and the end result is always that the work produced is never up to MY standard. But if I take Bruce’s idea of teaching the useful techniques, and letting a newbie develop their own style, their own identity which will reflect their individuality in their creations, then I have helped a person grow. There is no other way.At the same time, you have to watch for classical symptoms in your team. Check this out:

Too much horsing around with unrealistic stances and classic forms and rituals is just too artificial and mechanical, and doesn’t really prepare the student for actual combat. A guy could get clobbered while getting into this classical mess. Classical methods like these, which I consider a form of paralysis, only solidify and constrain what was once fluid. Their practitioners are merely blindly rehearsing routines and stunts that will lead nowhere. 

This is serious stuff. I often refer to this as “cut ‘n paste” coding from Google search results. Blindly hacking away old code is not code reuse, it just creates a maintenance nightmare. Software developers need to understand that the patterns and techniques that they use are only relevant in particular circumstances and contexts. Even if the pattern is relevant to solving the problem, it may be a poor choice because of other architectural considerations.Another word of advice from The Legend on coaching people:

A teacher must never impose this student to fit his favourite pattern; a good teacher functions as a pointer, exposing his student’s vulnerability (and) causing him to explore both internally and finally integrating himself with his being. 

Now this is some serious advice which I need to heed. We often lapse into a one-way-for-all approach to coaching. Is this not a symptom of our educational methods: the exclusion of individuality for the sake of mass education? The cookie cutter approach of modern schooling – Another Brick in the Wall, Pink Floyd style.

It’s all about attitude

I’m not even going to elaborate on this. Just read the following and let it rest with you, then start Kung Fu Coding … Bruce Lee style.

Do not be tense, just be ready, not thinking but not dreaming, not being set but being flexible. It is being “wholly” and quietly alive, aware and alert, ready for whatever may come.When one has reached maturity in the art, one will have a formless form. It is like ice dissolving in water. When one has no form, one can be all forms; when one has no style, he can fit in with any style.Finally, a Jeet Kune Do man who says Jeet Kune Do is exclusively Jeet Kune Do is simply not with it. He is still hung up on his self-closing resistance, in this case anchored down to reactionary pattern, and naturally is still bound by another modified pattern and can move within its limits. He has not digested the simple fact that truth exists outside all molds; pattern and awareness is never exclusive. 

Launching the Services Support Group

“Hello.  My name is Hope and I am a Service.  Last week I was asked by a View to do something.  I told the View that I can’t do it.  So he asked the Fat Controller.  The Controller sent me the same message and I just took exception.  What kind of service does he think I am?”

“Hello Hope.  We are glad you joined us.  You are not alone.  Look around the room.  We’re all struggling to find our own identity.  Those of us that have been around for a long time are still recovering from being forced to convert DomainObjects to DTOs.  The more recent ones feel like meaningless proxies, and last week we had a guy who thought he was a Service but he was just a HelperClass.”

“It’s as if I am losing touch with reality.  My own DomainObjects don’t even interact with me directly.  Now processes want a piece of me too.  I think I am schizophrenic.  Am I now a process?  A wrapper point for Transactions?  I swear to you, there are days when I even think I am a stored procedure!”

“Ohhhh, noooo!”

“But I know who I am. I am a Service.  I like working with DomainObjects.  They need me.  Somethimes they can’t do everything on their own, so I help out.  I complete their world and it makes me feel like I belong in the right place.  One guy even refactored me from the domain package to a services package.  Can you believe that!  Actually, now that I’ve said it aloud, I am not surprised that I feel more and more disoriented.”

“Disoriented?  Oh boy, we really can’t help you here.  You see we’re recovering from abusive Controllers and Views and when you told us the story in the beginning, we thought we could help you but you’re just a …”

“But that story is true.  Apparently there was this Process on other side of  this MessageBus that needed something and he asked the Fat Controller who got involved with View and then I got sent this message and …”

“WTF?!!  The Process asked the Controller…”

“Yeah!  You won’t understand … it’s after your time.  It’s really a WebServices Controller but I hear that he also feels abused and just wants some REST.  You think there’s a support group for Controllers?”

“Wait.  I remember this other crowd … uhhmmmm … sorry – those weren’t Controllers, those were Presenters working with Models and Views, but I used to be confused as a Delegator and I can …”

“You’re NOT HELPING!!!  I told you I am a Service!  And I am confused!  I want to be part of the domain again!  I feel disoriented!  And I …”

“And I told you that we can’t help you.  The truth is that you are DOA.”

“Dead on Arrival?”

“No! DisOriented Architecture.  You know … they don’t know where to put that, so it becomes a service.”

“But, but … I am a Service … <sniff>”

“YOU WERE NEVER A SERVICE!  YOU’RE ONLY HOPE!!!”

Balancing craftmanship and methodology

Carlo Kruger commented on my last blog post with reference to Martin Fowler’s blog post which is a concise view of a crazy blog and twitter war around software craftmanship.  For some reason, Carlo thinks that my last two blog posts (here and here) fall into this space. Either Carlo is baiting a hook for fun 😉 or he misunderstood me. Nevertheless, my dear friend, I shall reply.
Martin Fowler and Dan North put the customer’s derived value from the software as the focal point.  The craftmanship movement puts the code that derives the value as the focal point.  I don’t feel comfortable about either.  It is unbalanced.  We always need balance.  So, what will provide an equally powerful balancing force to either of these two focal points?  I think it is the economic viability of the code base.

In Let scrum die, the key message is that Scrum should not be the end goal but a means to get somewhere better.  At some point it will outlive it’s value and I propose a moment in time when that will happen, and one way to force this (i.e. plan the exit of the Scrum master).  I also describe “talented developers” which, perhaps, feels like a craftmanship-esque thing.  It’s not about that at all.  It’s about the balance that is described in the next to last paragraph: developers will represent the interest of the customer, and the code base is under control (i.e. it is economically viable).  Balance the focus of methodology with an the economic viability of the code base.

In You can’t let Scrum die, I draw attention to this lack of balance that leads to complacency.  I mention two craftmanship things to do with the code – remove duplication and express intentions.  Again, it’s not about this alone.  It’s about the balance that is needed.  That balance is described in the next to last paragraph: look at yourself and look at what you create (i.e. the code base).  The reason why I say look at the person next to you is because the economic viability of the code that you create will affect that other person also, including the entire organisation and its customers.  Balance the craftmanship with the methodology which is balanced by the economic viability of the code base.  This reduces to balancing craftmanship with the economic viability of the code base.

There is one area where I don’t know of a powerful enough balancing force.  In Politics of Software Delivery, I draw attention to organisational power grabbing that will always result in non-delivery.  I suggest raising the importance of the delivery value.  But I think this is still too weak a force to balance the power battle.  I don’t know how to fix that one.

Footnote: Jimmy Nilsson reminded me of an article he wrote about why TDD, Refactoring, DDD, and all such things matter.

Introducing the A-* Stack

Nowadays, software architecture and agile methodologies seem to be inextricably inter-twined. Everytime I have a chance for geek-talk with a bunch of software architects, there is always someone that will throw in some of the softer issues that deal with how we run our projects, how do we estimate, something about big design up front no-no’s, YAGNI, DRY and other buzzwords. Since architecture is full of metaphorical stacks of many kinds, I thought it might be useful to invent of an agile stack. Humor me, and let’s call it the A-* stack 🙂
I think there are several layers in A-*. I have no idea what is stacked on top of what, but Here is my A-* stack as I think of it right now, and we’ll try and refactor it later to gain deeper insight into the layers of responsibility and order that must evolve out of the chaos.

  • People Layer: This layer is responsible for establishing a team ethos. It is vital to creating a common work ethic in the team, shared values and principles. It is the lowest common denominator. In high conflict teams with high discord, things fall apart easily. Under these circumstances, you need to drop to philosophical introspection of your team values such as honesty, respect, reasons for existing on the project/or building the solution.
  • Project Management Layer: Managing a project founded on agile practices, even those that use agile practices partially, is no easy task. There is a dedicated layer of responsibility that keeps track of project velocity, prioritization of stories, facilitating feedback and managing change. Sure, we embrace change in agile projects but it still needs to be managed within the prioritized list of stories and other constraints of the project. This is different from traditional PMBOK style project management and deserves its own layer of responsibility.
  • Development Layer: This layer embraces the technical practices of the software developers. It includes niceties like continuous integration, test driven development, code refactoring, single code repositories that guarentee one version of the truth. This is, perhaps, the one layer that is best understood and have tangible actions at the code face.
  • Architecture and Design Layer: This layer is more than it’s really cool acronyms like YAGNI, DRY and BDUF. The focus is on gaining deeper insight into the problem domain. It very likely shares a gray and fuzzy area with the Development Layer and that’s ok. It really doesn’t matter that we have spillage into the development layer or vis versa. As long as we focus on gaining maximum understanding of the problem domain and modelling the solution as simply as as is possible.
  • Run-Time Layer: This is an oee one that I’ve dwelled on for a while. Sometimes the run-time environment really gets in the way and obstructs fluidity and rhythm in the development and architecture layer. It may well be the least agile of all layers in A-*. So, choose wisely … if you can. Let me explain a little further by example. The Ruby on Rails folk have made many screen casts that show how you can change code and you can just reload the page and, magically, the change is visible. Now compare that to someone writing EJB’s. Write, package, undeploy, deploy … it’s just painful, even if you are POJO+TDD inclined. The EJB container will bite you, eventually. So, in some respects the RoR runtime is more agile than the EJB runtime. (Aside: I think the only agile runtime in Java world is OSGi because it supports dynamic loading and unloading of classes and multiple versions classes in the same namespace. Now that’s agile!)
  • Environment Layer: The place where the team work is an equal contributor to agility. From how your workpace is layed out to desk configurations in an open plan office space, it is significant. Audible and visual communication is important and this may overlap ever so slightly with the people layer. I think the environment has a dedicated layer of responsibility in A-*.
  • Toolbox Layer: The tools you use can help you become more agile. I find that a flip chart, white board and multi-colored markers keeps me fluid and helps me progress rapidly, especially when I am working in the Architecture and Design Layer. We all have our special favorites that include the full blown IDE with our special key bindings, code diff tools, and even specialised items like shared whiteboards. I know of one team that has a Skype bot that acts as their JIRA interface – chatting to thet Skype bot allows them to update statuses and query JIRA. What tool ever keeps you agile has a place in this layer.

Perhaps, you have some other thoughts about what goes into A-* and what should be taken out. Maybe you have some real world insights that go beyond my meagre learning experiences. Drop me a note … I really would like to know how your A-* stacks up.

Patterns at the September SPIN Event

I suspect that many people did not understand what I meant about forces at play and that patterns describe a solution to bring some harmony among the forces in the problem in a particular context.  For the example of the airplane and wanting to serve the right meal to the right person, the challenge is to serve the meal without knowing about the seating arrangement on the plane, and still sequentially access each seat.  Let’s look at how to get rid of the need to know the seating arrangement.
We start with the solution where we need to know the arrangement of seating and number of seats too.  BTW, it’s ruby code.

for row in (0..29) do # 30 rows
    for pos in (0..5) do # seat A-F
       passenger = airplane.seats[row][pos]
       next if passenger.nil?
       passenger.serve_meal("nut free") if passenger.meal() == "nut free"
    end
end

Of course, if we know the seat number, for example, 15C, then we can do this.  But that does not help at all.

airplane.seats[14][2].serve_meal("nut free") if airplane.seats[14][2].meal() == "nut free"

But, we still expose the data structure of the seats.  So, let’s make it a little better by using the iterator pattern on the data structure for the seats.

airplane.seats.each do |row|
  row.each do | passenger |
    next if passenger.nil?
    passenger.serve_meal("nut free") if passenger.meal() == "nut free"
  end
end

We could be cuter and do something like this and hide the seats array, but we still expose the numbering scheme of the seating.

airplane.serve_meal("15C", "nut free")

So, we can have the iterator on the seats data structure, which helps a bit.  But we can make it a lot better if we put an iterator on the airplane itself. Now, we just care about occupied seats.

airplane.each_occupied_seat do |passenger|
  passenger.serve_meal("nut free") if passenger.meal()
 == "nut free"
end

In the airplane class, we have the following.

class airplane
  ...
  def each_occupied_seat &block
    @seats.each {|row| row.each { |pos| yield pos if not pos.nil?} }
  end
end

We are using iterators on the encapsulated seats structure and exposing a new iterator for the airplane. Also, we are only work with seat that has a passenger

So, we started out with a deep need to know the structure, layout and limits of the seating in the airplane. Then we started hiding the data structure for the seats, put iterators on this seats data structure which helped a bit.  But the real breakthrough happened when we started asking the airplane to just give us a way of sequentially accessing each seat that had a passenger.  No more conflicting forces, just a simple harmonious way to access each occupied seat on the plane.  And when the plane seating changes, we don’t care.