What makes a self-organizing team??

by Malcolm 1. November 2012 20:23

Capt Scrubhead, t’Unicorn, Rock Pig and 7 fingers in a lock

Self Organising Teams? I get a lot of push back on this – Especially when doing mingle implementations – People inevitably start down the “Access control” route!

“So I should make it so only QA’s can move a card to done! Right?”

Wrong! I think so anyway – Its true that the QA should be the only person actually exercising this change but don’t restrict it because you then create critical dependencies on someone in that group!

“But” they say, “If I don’t then ANYONE can do it!” – Correct – But how dumb would you have to be??

On most cars anyone inside the car can pull the handbrake! They don’t however because its stupid!

The idea that one of your team members will go into a mingle instance and maliciously alter your cards is the same as a passenger pulling the handbrake – If that is happening you have MUCH bigger problems than access control J

So why start a post about self-organizing teams with a rant about access control? Easy – If you force people into roles they will only do that role!

As an example I went on a canal boating holiday across the Pennines (A mountain range in the UK) last week – For anyone who has driven a boat on a canal (and particular one that goes over a mountain range) there are a LOT of locks – These things have loads of moving parts and take about 10 minutes each to cycle.

The tasks required are

  • Drain the lock if it’s full
  • Close sluice gates
  • Open the lower lock doors
  • Get boat in and stopped
  • Close lower lock doors
  • Open top sluice gates
  • Flood lock without destroying the boat
  • Open top doors
  • Get boat out of lock
  • Close top sluice gates
  • Close top lock doors
  • Go to next lock 

There is quite a lot to do – Now we had a particular lock we needed to get to by a time and that was all the “team” knew – We had 3 windlass handles – some ropes – a British waterways key and not enough time.

Now considering this was all for a mate’s birthday no one really wanted to turn around and give everyone jobs – it was a pretty free flowing affair

So here is what happened next

We had established a common goal – Get the boat to the controlled lock at the summit by 1 pm for our appointment passing through 10 locks and a few miles of canal en route. We all believed it was possible.

A couple of the guys grabbed some lock handles and hopped off the boat

At the first lock we were delayed to drain it – The ground crew discussed this while the lock cycled and dispatched one of the three with handles off up the canal to see if the next lock needed drained (Retrospective?)

They finished cycling the lock

When we got to the next one there was a brief delay as the doors opened and the lock crew again discussed how this one had gone – Again the forward lock guy headed off up the canal – I had inherited holding the rope to stop the boat from getting smashed – One of our team had taken over driving duties and the most hung over of us put the kettle on and kept the various team members fed on Tea / beer / etc.

When we got to the next one the lock had been prepped so well by the guy before all we needed to do was close the doors and start the water coming in – the lock crew had another brief retrospective and dispatched another of their crew up the lock to pass the revisions on to the forward lock hand with the British waterways key and from then on we were like a perfectly oiled machine cranking through the locks just about as fast as was conceivably possible. “Rock Pig” and “Capt Scrubhead” were plying everyone with tea, Biscuits, Beer, etc the team wanted for nothing in the performing of their primary duties and we were unstoppable

We didn’t make the appointment – Our initial estimate of 10 minutes / lock was out by about 5 minutes, which meant we were 20 minutes late (Yes I know the sums don’t add up but the other 30 minutes seemed to have been clawed back by sheer bloody mindedness of the team)

The team concerned had very rapidly worked out the most efficient way to achieve the goal in question Of their own volition– They self organized into the leanest lock crew you have ever seen.

At one of the last locks we caught another boat – I was driving by this point and the guy on the other boat asked me “So who is the skipper?” – I thought for a moment and realized we didn’t have one. No one was “in control” – everyone was executing towards a common goal to the very best of their abilities and communicating with every other team member – we didn’t need one! So I said what anyone would have

“Me” I replied J

The primary components that drove this brilliant self organization were:

The team were free to adjust anything they could control and discussed how to be more efficient at each lock
They all took it upon them selves as a personal challenge to achieve the impossible – It was the team Vs. the canal and they wanted to win!
Any and all needs they had regarding food / water – etc. were delivered quickly and efficiently by the tea and biscuits crew meaning they had little or no distractions from their primary task.

The end result of this particular adventure is that no one could have organized it any better – We all knew where we were and where we wanted to be and set about as a team finding the most efficient way of achieving this goal. I believe it was General George Patton who said “Tell a man what you want him to do and he will oblige, Tell him the goal you wish to achieve and he will astound you with his ingenuity” All to often we tell teams what we want them to do rather than the goal we want to get to – I think the latter is the best way to build a high performing agile team. 

SA and Wangler discussing finer points of Lock Etiquette with an anorak

t'Team!

Dave “t’Unicorn” - Forward lock and Crank Yanker 0
Chris “SA” Crank Yanker 1
Luke “Wangler” Crank Yanker 2
Richie “Capt. Massive” Persuader of stubborn Objects / Crank Yanker as required
Mick “Capt. Cutthroat” Caressing of Diesel – Running into things.
Yours truly “7 fingers” ropes and general dogs body
Lisa “Capt. Scrubhead” Provisions / Biscuits
Abigail “Rock Pig / Galley Slave ” Tea and general hung over duties.
Pete “Peg No Leg” anything a man with a genuinely broken leg was up to (Chucking ropes being one)

Lean Processing of Plutonium 238

by Malcolm 14. August 2012 23:32

Reduced Cycle time, reduced inventory and continuous flow in the production Plutonium 238.

I’m an avid reader of New Scientist and this made me smile(You will need to create a user account on New Scientist to read the article).

Basically NASA is going to run out of Pu 238 within 10 years, which they need to power deep space craft like voyager, Cassini etc.

Why?

Because Pu 238 traditionally has been a by-product of making weapons grade fissile materials, which we don’t do any more. 

 

(Reproduced from Page 6 of http://www.nasa.gov/pdf/636900main_Howe_Presentation.pdf)

The options open to NASA are an entirely new energy source (Unlikely in the time they have) Better solar (Bearing in mind a probe that generates its required power via a 1 m2 solar array in earth orbit would require a 2000 m2 solar array by the time it gets to Pluto!) or restart Pu 238 production.

Traditionally this is done by “soaking” a big lump of Np 237 (Neptunium) in a reactor kicking out a bunch of Neutrons that bombard the 237 turning it into 238.

This takes a BIG reactor about 6 to 12 months to perform (Think Big set up costs – Huge reactor cores, All the Big Infrastructure projects of the 60’s USA)

Or there is this proposal (The report the graph above is from) which on Page 13 describes creating the plutonium in a small university sized reactor core using small pellets of Neptunium – Basically reducing Cycle time, reducing inventory and using continuous flow in the production Plutonium 238 to increase delivery and lower costs.

In some ways could be considered a lean processing of Np 237 to Pu 238.

Why bother?

Well when NASA were buying Pu 238 from the Russians the market rate was about $12m / Kilo (Gold / Kg is approx . 51,000 USD making Pu 238 about 244 times as valuable as gold.) 

 

Tags:
Categories: Agile | Lean

Why is defining a minimally marketable feature set so tough?

by Malcolm 3. August 2012 18:31

So I wrote a game for a course I also wrote called “Agile fundamentals for product owners”, the course is a heavily cut down version of more in depth technical versions Thoughtworks offer but the point of the game is to pit two teams against each other for transportation contracts. The winning team each round is the one that gets their solution to market fastest. OK so a little contrived but a few interesting things happen when you play the game.

1. The players start aggressively discounting features that aren’t essential – They suddenly really “get” the concept of a minimally marketable feature set.

2. When you ask them if they do this in their existing projects they unanimously say “no”.

3. the drive to do this comes from the fact they can see the other team approaching the same problem.

Which got me to wondering why they find this so hard in their actual business? The only real difference is they can’t see the other team they are competing with, but you can bet your bottom dollar they are out there somewhere.

Your only saving grace is the other team can’t see you either!

The reality of this situation is still the competitor who gets to market faster usually wins! Be it through understanding clearly what their minimally marketable feature set is or a good Continuous Delivery (CD) pipeline or ever through sheer bloody mindedness, I’d suggest Minimally marketable feature sets is probably the most important. If you couple that with a CD pipeline you are now in a very powerful position! – You now have the ability to repeatedly get changes into production that solves the problem faster than anyone else (or at absolute worst the same speed).

The winner in this situation is the team that really understand what their minimally marketable feature set is.

Do you?

 

Unity IoC container: tips, tricks and dirty hacks

by Marcin Kaluza 14. April 2012 08:20

It took me two years to write this post. Each time I started writing it, it suffered from gradual and seemingly unavoidable feature creep: should I mention dependency inversion principle? What about SOLID principles in general? What about testability? The list goes on and on. But it was a recent interesting discussion with a friend about the use (and abuse) of dependency injection that prompted me to finally finish it.

I have been using Unity IoC container for a while now and in the process I have managed to ”abuse” it in every possible way so I hope this post covers some of the more advanced and intricate usage scenarios you may ever come across.

Trivial case

In case you have never used Unity before, the behaviour of the container is pretty trivial: call Register<T,TImpl>() on a number of types then make a call to Resolve<T> and with a bit of luck you will get a instance of it:

    [TestFixture]
    class TrivialTests
    {
        [Test]
        public void TrivialOne()
        {
            var container = new UnityContainer();

            container.RegisterType<IBar, Bar>();

            var instance = container.Resolve<IBar>();

            Assert.NotNull(instance);
        }
    }

    internal class Bar : IBar {}
    internal interface IBar {}

Implementing a factory with Unity

Unity is not only able to resolve an implementation of a particular interface; it may also help in resolving dependencies when the type to be instantiated is known (even if it has not been registered with the container):

    [TestFixture]
    public class ObjectBuildupTest
    {
        [Test]
        public void ObjectBuildup()
        {
            var container = new UnityContainer();
            container.RegisterType<ISomeService, SomeService>();

            var anInstance = container.Resolve<ObjectWithDependencies>();

            Assert.NotNull(anInstance);
        }
    }

    public class ObjectWithDependencies
    {
        public ObjectWithDependencies(ISomeService  someService)
        {
            if (someService == null) throw new ArgumentNullException("someService");
        }
    }

    public interface ISomeService {}
    public class SomeService : ISomeService {}

As you can see from the code above, even though the type “ObjectWithDependencies” has not been registered with the container, Unity was able to correctly instantiate it and inject it with previously registered dependency. Such functionality may come very useful when implementing a factory: we know what we want to instantiate but not necessarily want to be bothered with instantiating all the dependencies. The following sample illustrates this approach.

    [TestFixture]
    public class FactoryTest
    {
        [Test]
        public void UnityBasedFactoryTest()
        {
            var container = new UnityContainer();

            container.RegisterType<ISomeService, SomeService>();
            container.RegisterType<ISomeFactory, SomeFactory>();

            var factory = container.Resolve<ISomeFactory>();

            Assert.NotNull(factory.ManufactureAnObject("A"));
        }
    }

    public interface ISomeFactory
    {
        ICommonInterface ManufactureAnObject(string anArgument);
    }

    public class SomeFactory : ISomeFactory
    {
        private readonly IUnityContainer _container;

        public SomeFactory(IUnityContainer container)
        {
            _container = container;
        }

        public ICommonInterface ManufactureAnObject(string anArgument)
        {
            switch(anArgument)
            {
                case "A":
                    return _container.Resolve<TypeA>();
                case "B":
                    return _container.Resolve<TypeB>();
                default:
                    throw new NotSupportedException();
            }
        }
    }

    public interface ICommonInterface {}

    public class TypeB : ICommonInterface
    {
        public TypeB(ISomeService someService)
        {            
        }
    }

    public class TypeA : ICommonInterface
    {
        public TypeA(ISomeService someService)
        {            
        }
    }

As you have probably noticed our factory requires an instance of IUnityContainer, luckily the container auto-registers itself, so whenever and instance of IUnityContainer is required, one will be injected without any fuss. Purists may frown upon direct use of the container, but in my opinion this is one of the very rare cases where it can be justified.

Multiple implementations of the same contract

The following example illustrates how to register multiple implementations of the same interface. Each registration is done with a particular key (quite a common feature among IoC containers) and then when resolving it we need to specify the key to get a particular implementation:

    [TestFixture]
    public class MultipleImplementationsTests
    {
        [Test]
        public void MultipleImplementations_ResolveCorrectly()
        {
            var container = new UnityContainer();
            container.RegisterType<IFooBar, SomeFooBar>("first");
            container.RegisterType<IFooBar, OtherFooBar>("second");

            Assert.NotNull(container.Resolve<IFooBar>("first"));
            Assert.NotNull(container.Resolve<IFooBar>("second"));
            Assert.Throws<ResolutionFailedException>(() => container.Resolve<IFooBar>());
        }
    }

    public interface IFooBar {}
    public class OtherFooBar : IFooBar {}
    public class SomeFooBar : IFooBar {}

This functionality can again be used to implement a factory of sorts but in general it is not that interesting until we get to the next point.

Building a composite

Having a multiple implementations of a particular contract registered with the container is the stepping stone to building a composite, as the following sample illustrates:

    [TestFixture]
    public class CompositeTests
    {
        [Test]
        public void BuildComposite()
        {
            var container = new UnityContainer();
            container.RegisterType<IFoo, SomeFoo>("first");
            container.RegisterType<IFoo, AnotherFoo>("second");
            container.RegisterType<IFoo, CompositeFoo>();

            var instanceOfFoo = container.Resolve<IFoo>();

            Assert.IsInstanceOf<CompositeFoo>(instanceOfFoo);
        }
    }

    public class CompositeFoo : IFoo
    {
        public CompositeFoo(IFoo[] others)
        {
            Debug.Assert(others != null);
            Debug.Assert(others.Any());
        }
    }

    public class AnotherFoo : IFoo {}
    public class SomeFoo : IFoo {}
    public interface IFoo {}

Composite in this case “consumes” an array of child objects and in a sense “sucks in” every implementation of IFoo registered with a key. This is an important aspect: if you were to register composite with a key, it would try to instantiate itself leading in immediately to StackOverflowException. The other interesting aspect is the fact that the composite requires an argument of type IChild[]. I am not sure about you but I personally find arrays very much 20th century and would rather have IEnumerable<IChild> injected, sadly Unity does not support it out of the box. There is however a workaround for it which I will share with you later.

Building chain of responsibility

Another interesting use case for naming your registrations is the implementation of Chain Of Responsibility pattern as the following sample illustrates:

    [TestFixture]
    class ChainOfResponsibilityTests
    {
        [Test]
        public void BuildChain()
        {
            var container = new UnityContainer();
            container.RegisterType<IChainLink, LastLink>("last");
            container.RegisterType<IChainLink, SecondLink>("second",
                                                           new InjectionConstructor(
                                                               new ResolvedParameter<IChainLink>("last")));
            container.RegisterType<IChainLink, FirstLink>(new InjectionConstructor(
                                                               new ResolvedParameter<IChainLink>("second")));

            var firstLink = container.Resolve<IChainLink>();

            Assert.IsInstanceOf<FirstLink>(firstLink);
        }
    }

    internal interface IChainLink {}

    internal class FirstLink : IChainLink
    {
        public FirstLink(IChainLink nextLink)
        {
            if (nextLink == null) throw new ArgumentNullException("nextLink");
        }
    }

    internal class SecondLink : IChainLink
    {
        public SecondLink(IChainLink nextLink)
        {
            if (nextLink == null) throw new ArgumentNullException("nextLink");
        }
    }

    internal class LastLink : IChainLink {}

 

In this case we need to resort to pointing each registered element of the chain to its predecessor which is achieved using ResolvedParameter<T>(name). This way we have full control as to what registration gets injected where. This may come helpful in cases where different implementations of the same contract are to be injected in different places.

Injecting the same object in multiple places in the object graph (semi-singleton)

Unity has a very interesting feature which allows the same object to be injected and shared in multiple places in the object graph. Let’s consider the following object diagram

:image

As you can see both the parent and the children contain references to an instance of Service. Standard behaviour of the IoC container is to inject new instance of the dependency into every object in the graph, this however may not be what we want:

image

In order to solve this conundrum Unity provides PerResolveLifetimeManager which within a single call to Resolve<T>() will create an instance of particular type and reuse it wherever required as the next sample illustrates:

    [TestFixture]
    public class PerResolutionLifetimeTests
    {
        [Test]
        public void Regiser_WithPerResolveLifetimeManager_ContainerInjectsSameInstance()
        {
            var container = new UnityContainer();
            container.RegisterType<IService, AService>(new PerResolveLifetimeManager());
            container.RegisterType<IParent, Parent>();
            container.RegisterType<IChild, Child>();

            var parent = container.Resolve<IParent>();

            Assert.AreSame(parent.Service, parent.Child.Service);
        }
    }

    public interface IService {}
    public class AService : IService {}
    public interface IChild
    {
        IService Service { get; set; }
    }

    public class Child : IChild
    {
        public IService Service { get; set; }

        public Child(IService service)
        {
            Service = service;
        }
    }

    public interface IParent
    {
        IChild Child { get; set; }
        IService Service { get; set; }
    }

    public class Parent : IParent
    {
        public IChild Child { get; set; }
        public IService Service { get; set; }

        public Parent(IChild child, IService service)
        {
            Child = child;
            Service = service;
        }
    }

Eternal problem: Chicken and Egg

Now there is an interesting chicken and egg problem which may seem to be impossible to solve using IoC container:

    
    public interface IEgg
    {
        IChicken Chicken { get; set; }
    }

    public interface IChicken
    {
        IEgg Egg { get; set; }
    }

    public class Chicken : IChicken
    {
        public IEgg Egg { get; set; }
    }

    public class Egg : IEgg
    {
        public Egg(IChicken chicken)
        {
            Chicken = chicken;
        }

        public IChicken Chicken
        {
            get;
            set;
        }
    }

As you can see we have a circular dependency going on here (Chicken “contains” an egg, while the egg points to its parent). This may seem to be a hopeless case but there is a solution to it: we need to combine property injection with PerResolveLifetimeManager:

[Test]
public void BuildObjectGraphWithCircularDependency()
{
    var container = new UnityContainer();

    container.RegisterType<IChicken, Chicken>(new PerResolveLifetimeManager(), new InjectionProperty("Egg"));
    container.RegisterType<IEgg, Egg>();

    var chicken = container.Resolve<IChicken>();

    Assert.AreSame(chicken, chicken.Egg.Chicken);
}

The magic above works as follows: container instantiates an instance of the Chicken class and then tries to resolve the Egg dependency. Egg in turn requires another instance of Chicken, luckily the Chicken class has been registered with PerResolveLifetimeManager which means it that instance of it can be reused in building the Egg. I think the case above is the only one I can think of where the use of property injection could be justified.

IoC and Interface segregation principle

There are some cases where a single type implements multiple contracts (interfaces). If you follow interface segregation principle this may lead to some troublesome cases:

[Test]
public void Resolve_ObjectDependantOnBaseInterface_ResolutionFails()
{
    var container = new UnityContainer();
    
    container.RegisterType<IDerived, Derived>();
    container.RegisterType<IDependsOnBase, DependsOnBase>();

    Assert.Throws<ResolutionFailedException>(() => container.Resolve<IDependsOnBase>());
}

public interface IBase { }
internal interface IDerived : IBase { }
internal class Derived : IDerived { }

public interface IDependsOnBase { }

public class DependsOnBase : IDependsOnBase
{
     public DependsOnBase(IBase dependency){}
}

As you can see from the code above, Derived implements IDerived which in turn is an instance of IBase. Inspite of that, resolution of DependsOnBase fails miserably. The reason is obviously the fact that there is no explicit implementation of IBase registered with the container. We could circumvent the problem by registering the Derived as type implementing the IBase interface. This approach would work but what if Derived implements more than one interface? There is however an easy way to work around the issue and this requires a hint to the container that instead of IBase it should search for an implementation of IDerived:

[Test]
public void Resolve_ObjectDependantOnBaseInterface_ResolutionSucceeds()
{
    var container = new UnityContainer();

    container.RegisterType<IDerived, Derived>();
    container.RegisterType<IDependsOnBase, DependsOnBase>(new InjectionConstructor(typeof(IDerived)));

    Assert.DoesNotThrow(() => container.Resolve<IDependsOnBase>());
}

This way btw it is the way to construct a composite using IEnumerable<> instead of an array as mentioned previously.

Overriding constructor parameters

The final set of Unity tricks deals with overriding constructor parameters. As you may remember we did this to a certain extent when registering individual elements of the chain of responsibility. There are two ways to do it: we can either instruct container at the time of registration to use specific instance of the parameters, or override parameter value at the time of resolution. Following sample illustrates both techniques.

[TestFixture]
public class ConstructorParameters
{
    [Test]
    public void OverridingCtorParams()
    {
        var container = new UnityContainer();
        container.RegisterType<SomeType>(new InjectionConstructor("Boo"));
        
        var firstInstance = container.Resolve<SomeType>();
        Assert.AreEqual("Boo", firstInstance.Message);

        var secondInstance = container.Resolve<SomeType>( new ParameterOverride("message", "Baa"));
        Assert.AreEqual("Baa", secondInstance.Message);
    }
}

public class SomeType
{
    public string Message { get; set; }

    public SomeType(string message)
    {
        Message = message;
    }
}
Tags:
Categories: C# | Software Development