jasperblues/Typhoon — pull request #101 by drodriguez (2013-11-11 21:07:36+00:00)
Title: Factory provider

`TyphoonFactoryProvider` implements a kind of automatic creation of factory classes for the user code. The user only has to provide a protocol with the interface of the factory she wants to create, and some “glue” code, and the factory will be created at runtime for her.

The idea for the `TyphoonFactoryProvider` comes from [Guice AssistedInject][1]. Since the ObjC runtime is a little less typed than Java’s, some of the “automagic” that Guice guys manage to pull off can’t be reproduced in Typhoon. The dependencies has to be wired by hand, and the body of the factory methods have to be provided explicitly.

Even with those drawbacks, the code the user has to write is reduced by a lot of lines (no need to write the factory initializer, no need to declare the storage for the dependencies, most of the implementation block…), so I think is still useful.

There is a little “example” written as documentation for the `TyphoonFactoryProvider` class, and the tests use the same example.

I also fixed some problems I found while compiling.

Known limitation: for each protocol you only can have one factory “implementation”. If you invoke `TyphoonFactoryProvider` twice for a protocol the “implementation” will be the first one to run at runtime. This limitation can be easily removed, but I don’t know if the runtime will create one new class per definition or one per use of the definition.

PD: I was not able to run the test in iOS, I suppose they are not broken, but…

[1]: https://code.google.com/p/google-guice/wiki/AssistedInject