0
Dawn
standing on the shoulders of giants
What is Dawn

• Dependency Injection library inspired by
  Google Guice
• Notification system based on types
• Simple type ...
Why?

• Unhappy with my options
• Small issues that have large consequences
• Flash and Flex
• Small (~12K)
• A new breed ...
What its not

• MVC, MVP ... you structure your app
• Plugin architecture
• Aiming to take over the world
Some Design Principles
• Testing is vital
• Play to language strengths
• Type safety is winfull
• Configuration is no fun (...
Dependency Injection
   a lot of fuss about nothing
TheDoctor
TheDoctor


  Tardis
TheDoctor


Assistant     Tardis
TheDoctor


Assistant     Tardis    Mission
TheDoctor


IAssistant     Tardis    IMission
TheDoctor


     IAssistant        Tardis    IMission



RoseTyler
        DonnaNoble
TheDoctor


     IAssistant        Tardis         IMission



RoseTyler                        Cybermen

        DonnaNobl...
Object graph of
 TheDoctor

                          TheDoctor


          IAssistant        Tardis         IMission



 ...
Creating The Doctor
•   Construct dependencies within the class

•   Service locator

•   Factories

•   DI By hand
Doing it by hand
class TheDoctor{
  public var mission:IMission;
  public var assistant:IAssistant;
  public var tardis:Ta...
Doing it by hand
var doctor:TheDoctor = new TheDoctor();
Doing it by hand
var tardis:Tardis = new Tardis();
var doctor:TheDoctor = new TheDoctor();
doctor.tardis = tardis;
Doing it by hand
var assistant:IAssistant = new RoseTyler();
var tardis:Tardis = new Tardis();
var doctor:TheDoctor = new ...
Doing it by hand
var mission:IMission = new Daleks();
var assistant:IAssistant = new RoseTyler();
var tardis:Tardis = new ...
Doing it by hand
•   Thats a lot of code to create a Doctor

•   More code to maintain

•   Fragile to change

•   Client ...
Dependency Injection
 is all about creating
    object graphs!
Dawn DI
•   How can object creation be automated and easy?

•   Meets design principles

•   Thank you Google Guice!
Configure the Doctor
Configure the Doctor
1. Indicate the dependencies
Configure the Doctor
1. Indicate the dependencies

2. Chose an assistant
Configure the Doctor
1. Indicate the dependencies

2. Chose an assistant

3. Chose a mission
Configure the Doctor
class TheDoctor{
  public var mission:IMission;
  public var assistant:IAssistant;
  public var tardis...
Configure the Doctor
class TheDoctor{
  [Inject] public var mission:IMission;
  [Inject] public var assistant:IAssistant;
 ...
Configure the Doctor
class Config implements IConfig{
   public function create(mapper:IMapper):void{
      mapper.map(IAssis...
Create the Doc
var mission:IMission = new Daleks();
var assistant:IAssistant = new RoseTyler();
var tardis:Tardis = new Ta...
Create the Doc
Create the Doc


builder.getObject(TheDoctor)
Create the Doc

var doctor:TheDoctor;
var builder:IBuilder = new Builder(new Config());

doctor = builder.getObject(TheDoct...
Dawn DI
•   You write less code (no XML)

•   Configuration is ActionScript (and small)

•   Classes are compiled into final...
Dawn DI
•   Scopes - Singleton or Transient

•   Map toFactory/toInstance for construction control

•   Modular configurati...
FP-183
[Inject] Dawn DI
•   Simple

•   Light

•   Type safe

•   Test friendly

•   Terse
Notifications
decoupling without the compromise
Dawn Notifications

•   Type based

•   Closure friendly

•   Static free
The Problem
The Problem
View


View


View


View
The Problem
View


View
            Data

View


View
The Problem
View


View
            Data
            Data
View


View
The Problem
View


View
            Data
            Data
             Data
View


View
The Problem
View


View
            Data
            Data
             Data
              Data
View


View
The Problem
View


View
            Data
            Data
             Data
              Data
View


View
The Problem
View


View
            Data
            Data
             Data
              Data
View


View
The Problem
View


View
            Data
            Data
             Data
              Data
View


View
The Problem
View


View
            Data
            Data
             Data
              Data
View


View
The Problem
View


View
            Data
            Data
             Data
              Data
View


View
The Problem
View


View
            Data
            Data
             Data
              Data
View


View
The Problem
View


View
            Data
            Data
             Data
              Data
View


View
The Problem
View


View
            Data
            Data
             Data
              Data
View


View
The Problem
View


View
            Data
            Data
             Data
              Data
View


View
The Problem
       Gets a little confusing?
View


View
                 Data
                 Data
                  Data...
Decouple and Scale
Decouple and Scale
View


View


View


View
Decouple and Scale
View


View

             Data
             Data
              Data
               Data
View


View
Decouple and Scale
         Notification System
View


View

                    Data
                    Data
            ...
Decouple and Scale
         Notification System
View


View

                    Data
                    Data
            ...
Decouple and Scale
         Notification System
View


View

                    Data
                    Data
            ...
Type based
Type based


addEventListener(type:String,closure:Function...)
Type based


addEventListener(type:String,closure:Function...)

   addCallback(type:Class,closure:Function);
Why Types
Why Types
•   Make full use of polymorphism
    IEventType, BaseRpcEvent, com.wibble.Woo
Why Types
•   Make full use of polymorphism
    IEventType, BaseRpcEvent, com.wibble.Woo

•   Avoids meaningless statics
 ...
Why Types
•   Make full use of polymorphism
    IEventType, BaseRpcEvent, com.wibble.Woo

•   Avoids meaningless statics
 ...
Why Types
•   Make full use of polymorphism
    IEventType, BaseRpcEvent, com.wibble.Woo

•   Avoids meaningless statics
 ...
Closure unfriendly

addEventListener(Event.ADDED,
   function(event:Event):void{
       trace(“haha, Try removing me”)
   ...
Closure friendly!
Closure friendly!

var listener:IListenerRegistration =
   bus.addCallback(ILogAction,
       function(note:ILogAction):vo...
Closure friendly!

var listener:IListenerRegistration =
   bus.addCallback(ILogAction,
       function(note:ILogAction):vo...
Triggering
class TadPole{
     [Inject] public var bus:INotificationBus;

    [DependenciesInjected]
    public function in...
Dawn Notifications
•   Simple API

•   Use the language, closures are good!

•   Types are smarter then strings (Duh!)

•  ...
Commands
simple tools are easy to build with
Commands
• easy to maintain stateless goodies
• central point for lots of easy wins
 • queueing
 • cacheing
 • handle erro...
Commands
• ICommand interfaces force casting
 •   execute(param:Object):void

• How to access other application objects
 •...
Dawn Commands

• Injectable
• Type safe
• Type based DRY configuration
Dawn Commands
class MakeHayCommand{
      [Inject] public var barn:Barn;


     [Execute] public function execute(note:Mak...
Dawn Commands
class MakeHayCommand{
    [Inject] public var barn:Barn;


     [Execute] public function execute(note:MakeH...
Dawn Commands
class MakeHayCommand{
      [Inject] public var barn:Barn;


    [Execute] public function execute(note:Make...
Dawn Commands
class MakeHayCommand{
      [Inject] public var barn:Barn;


     [Execute] public function execute(note:Mak...
Dawn Commands



 addCommand(MakeHayCommand);
Dawn

• Dependency Injection
• Notifications
• Commands
http://github.com/
  sammyt/dawn
Questions etc?
Dawn - Actionscript Library
Upcoming SlideShare
Loading in...5
×

Dawn - Actionscript Library

1,927

Published on

dependency injection, notifications, type safe commands and actionscript gripes

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,927
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
22
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Dawn - Actionscript Library"

  1. 1. Dawn standing on the shoulders of giants
  2. 2. What is Dawn • Dependency Injection library inspired by Google Guice • Notification system based on types • Simple type safe command pattern 
  3. 3. Why? • Unhappy with my options • Small issues that have large consequences • Flash and Flex • Small (~12K) • A new breed of project
  4. 4. What its not • MVC, MVP ... you structure your app • Plugin architecture • Aiming to take over the world
  5. 5. Some Design Principles • Testing is vital • Play to language strengths • Type safety is winfull • Configuration is no fun (keep it DRY) • Static state is bad • Types are better than strings
  6. 6. Dependency Injection a lot of fuss about nothing
  7. 7. TheDoctor
  8. 8. TheDoctor Tardis
  9. 9. TheDoctor Assistant Tardis
  10. 10. TheDoctor Assistant Tardis Mission
  11. 11. TheDoctor IAssistant Tardis IMission
  12. 12. TheDoctor IAssistant Tardis IMission RoseTyler DonnaNoble
  13. 13. TheDoctor IAssistant Tardis IMission RoseTyler Cybermen DonnaNoble Daleks
  14. 14. Object graph of TheDoctor TheDoctor IAssistant Tardis IMission RoseTyler Cybermen DonnaNoble Daleks
  15. 15. Creating The Doctor • Construct dependencies within the class • Service locator • Factories • DI By hand
  16. 16. Doing it by hand class TheDoctor{ public var mission:IMission; public var assistant:IAssistant; public var tardis:Tardis; }
  17. 17. Doing it by hand var doctor:TheDoctor = new TheDoctor();
  18. 18. Doing it by hand var tardis:Tardis = new Tardis(); var doctor:TheDoctor = new TheDoctor(); doctor.tardis = tardis;
  19. 19. Doing it by hand var assistant:IAssistant = new RoseTyler(); var tardis:Tardis = new Tardis(); var doctor:TheDoctor = new TheDoctor(); doctor.tardis = tardis; doctor.assistant = assistant;
  20. 20. Doing it by hand var mission:IMission = new Daleks(); var assistant:IAssistant = new RoseTyler(); var tardis:Tardis = new Tardis(); var doctor:TheDoctor = new TheDoctor(); doctor.tardis = tardis; doctor.assistant = assistant; doctor.mission = mission;
  21. 21. Doing it by hand • Thats a lot of code to create a Doctor • More code to maintain • Fragile to change • Client of TheDoctor must know inner workings (encapsulation fail) • Construction followed simple patterns
  22. 22. Dependency Injection is all about creating object graphs!
  23. 23. Dawn DI • How can object creation be automated and easy? • Meets design principles • Thank you Google Guice!
  24. 24. Configure the Doctor
  25. 25. Configure the Doctor 1. Indicate the dependencies
  26. 26. Configure the Doctor 1. Indicate the dependencies 2. Chose an assistant
  27. 27. Configure the Doctor 1. Indicate the dependencies 2. Chose an assistant 3. Chose a mission
  28. 28. Configure the Doctor class TheDoctor{ public var mission:IMission; public var assistant:IAssistant; public var tardis:Tardis; }
  29. 29. Configure the Doctor class TheDoctor{ [Inject] public var mission:IMission; [Inject] public var assistant:IAssistant; [Inject] public var tardis:Tardis; }
  30. 30. Configure the Doctor class Config implements IConfig{ public function create(mapper:IMapper):void{ mapper.map(IAssistant).toClass(RoseTyler); mapper.map(IMission).toClass(Daleks); } }
  31. 31. Create the Doc var mission:IMission = new Daleks(); var assistant:IAssistant = new RoseTyler(); var tardis:Tardis = new Tardis(); var doctor:TheDoctor = new TheDoctor(); doctor.tardis = tardis; doctor.assistant = assistant; doctor.mission = mission;
  32. 32. Create the Doc
  33. 33. Create the Doc builder.getObject(TheDoctor)
  34. 34. Create the Doc var doctor:TheDoctor; var builder:IBuilder = new Builder(new Config()); doctor = builder.getObject(TheDoctor) as TheDoctor;
  35. 35. Dawn DI • You write less code (no XML) • Configuration is ActionScript (and small) • Classes are compiled into final swf • Agile code, refactor structure fast and easily • Testing is easy, second nature • DI helps you write better code! • Dawn makes DI easy!
  36. 36. Dawn DI • Scopes - Singleton or Transient • Map toFactory/toInstance for construction control • Modular configuration • Name injections • Inject properties like strings or arrays • Optional injections • Inject via mutators or properties
  37. 37. FP-183
  38. 38. [Inject] Dawn DI • Simple • Light • Type safe • Test friendly • Terse
  39. 39. Notifications decoupling without the compromise
  40. 40. Dawn Notifications • Type based • Closure friendly • Static free
  41. 41. The Problem
  42. 42. The Problem View View View View
  43. 43. The Problem View View Data View View
  44. 44. The Problem View View Data Data View View
  45. 45. The Problem View View Data Data Data View View
  46. 46. The Problem View View Data Data Data Data View View
  47. 47. The Problem View View Data Data Data Data View View
  48. 48. The Problem View View Data Data Data Data View View
  49. 49. The Problem View View Data Data Data Data View View
  50. 50. The Problem View View Data Data Data Data View View
  51. 51. The Problem View View Data Data Data Data View View
  52. 52. The Problem View View Data Data Data Data View View
  53. 53. The Problem View View Data Data Data Data View View
  54. 54. The Problem View View Data Data Data Data View View
  55. 55. The Problem View View Data Data Data Data View View
  56. 56. The Problem Gets a little confusing? View View Data Data Data Data View View
  57. 57. Decouple and Scale
  58. 58. Decouple and Scale View View View View
  59. 59. Decouple and Scale View View Data Data Data Data View View
  60. 60. Decouple and Scale Notification System View View Data Data Data Data View View
  61. 61. Decouple and Scale Notification System View View Data Data Data Data View View
  62. 62. Decouple and Scale Notification System View View Data Data Data Data View View
  63. 63. Type based
  64. 64. Type based addEventListener(type:String,closure:Function...)
  65. 65. Type based addEventListener(type:String,closure:Function...) addCallback(type:Class,closure:Function);
  66. 66. Why Types
  67. 67. Why Types • Make full use of polymorphism IEventType, BaseRpcEvent, com.wibble.Woo
  68. 68. Why Types • Make full use of polymorphism IEventType, BaseRpcEvent, com.wibble.Woo • Avoids meaningless statics FinishedBaconEvent.FINISHED_BACON
  69. 69. Why Types • Make full use of polymorphism IEventType, BaseRpcEvent, com.wibble.Woo • Avoids meaningless statics FinishedBaconEvent.FINISHED_BACON • No hidden collisions MyEvent.CLOSE == Event.CLOSE == FAIL
  70. 70. Why Types • Make full use of polymorphism IEventType, BaseRpcEvent, com.wibble.Woo • Avoids meaningless statics FinishedBaconEvent.FINISHED_BACON • No hidden collisions MyEvent.CLOSE == Event.CLOSE == FAIL • No switch statements switch( notification.getName() )
  71. 71. Closure unfriendly addEventListener(Event.ADDED, function(event:Event):void{ trace(“haha, Try removing me”) });
  72. 72. Closure friendly!
  73. 73. Closure friendly! var listener:IListenerRegistration = bus.addCallback(ILogAction, function(note:ILogAction):void{ } );
  74. 74. Closure friendly! var listener:IListenerRegistration = bus.addCallback(ILogAction, function(note:ILogAction):void{ } ); listener.remove();
  75. 75. Triggering class TadPole{ [Inject] public var bus:INotificationBus; [DependenciesInjected] public function init():void{ bus.trigger(new TadPoleCreated()); } }
  76. 76. Dawn Notifications • Simple API • Use the language, closures are good! • Types are smarter then strings (Duh!) • Reduce the complexity of application structure
  77. 77. Commands simple tools are easy to build with
  78. 78. Commands • easy to maintain stateless goodies • central point for lots of easy wins • queueing • cacheing • handle errors • etc etc.
  79. 79. Commands • ICommand interfaces force casting • execute(param:Object):void • How to access other application objects • Model.getInstance(); • Mapping Strings to Commands is fiddly (more developer discipline) • registerCommand(Notify.GET_THING, GetThingCommand);
  80. 80. Dawn Commands • Injectable • Type safe • Type based DRY configuration
  81. 81. Dawn Commands class MakeHayCommand{ [Inject] public var barn:Barn; [Execute] public function execute(note:MakeHay):void{ barn.makeHay(note.howMuchHay); } }
  82. 82. Dawn Commands class MakeHayCommand{ [Inject] public var barn:Barn; [Execute] public function execute(note:MakeHay):void{ barn.makeHay(note.howMuchHay); } }
  83. 83. Dawn Commands class MakeHayCommand{ [Inject] public var barn:Barn; [Execute] public function execute(note:MakeHay):void{ barn.makeHay(note.howMuchHay); } }
  84. 84. Dawn Commands class MakeHayCommand{ [Inject] public var barn:Barn; [Execute] public function execute(note:MakeHay):void{ barn.makeHay(note.howMuchHay); } }
  85. 85. Dawn Commands addCommand(MakeHayCommand);
  86. 86. Dawn • Dependency Injection • Notifications • Commands
  87. 87. http://github.com/ sammyt/dawn
  88. 88. Questions etc?
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×