Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Structuring your flex application with swiz

2,314 views

Published on

Published in: Technology
  • Be the first to comment

Structuring your flex application with swiz

  1. 1. Structuring Flex applications with the Swiz framework<br />Spreker: Jamie Craane<br />
  2. 2. Agenda<br />Presentationpatterns<br />Swiz<br />Q&A<br />
  3. 3. PresentationPatterns<br />Autonomous view<br />Presentation Model<br />Code Behind<br />Model View Presenter<br />Model View Controller<br />And many more…<br />
  4. 4. Autonomous view<br />View<br />
  5. 5. Code Behind<br />View<br />MXML<br />Code-behind<br />Eventhandlers<br />Data Model<br />
  6. 6. Model View Presenter<br />Uses contract to <br />read/write view data<br />View<br />Presenter<br />Read/write<br />model<br />Model<br />
  7. 7. Presentation Model<br />View<br />Presentation<br />model<br />Model<br />
  8. 8. Model View Controller<br />Responds to user events<br />View<br />Controller<br />Updates<br />model<br />Model<br />Notifies view<br />
  9. 9.
  10. 10. MVC<br />View<br />Model<br />Service<br />display<br />update<br />update<br />mediator<br />update<br />invokes<br />invokes<br />invokes<br />Controller<br />
  11. 11. Model: Representing State<br /><ul><li>Representsclient state
  12. 12. [Bindable] : dispatcheseventon state change</li></ul>session<br />user<br />personList<br />taskList<br />selectedPerson<br />
  13. 13. View: Presentation and Interaction<br />View<br />Model<br />References<br />personlist<br />taskdetails<br />Notifies<br /><ul><li>Presents model to the user
  14. 14. Responds to model changes, ({} databinding)
  15. 15. Responds to user actions, (Declarativeeventhandling)
  16. 16. MostlyMXML</li></li></ul><li>Controller: ExposeActions<br /><ul><li>User-initiatedactions
  17. 17. Invokes services
  18. 18. Updates model</li></ul>View<br />Controller<br />call<br />Service<br />Invoke<br />Model<br />Updates<br />
  19. 19. Service: Encapsulatesbackends<br />Services<br />PersonService<br />TaskService<br />PersonService<br />Mock<br /><ul><li>Service callsremotedestinations
  20. 20. HttpServiceorRemoteObject (ie. BlazeDS)
  21. 21. Returns anASyncToken
  22. 22. Logical place forstubs</li></li></ul><li>Mediators: update view<br />User-initiatedactions<br />Updates view<br />Updates model (ifneeded)<br />Mediator<br />Interface<br />View<br />call<br />View<br />Updates<br />Model<br />Updates<br />
  23. 23. Swiz<br />Micro architecture and Dependency Injection framework<br />
  24. 24. MircoArchitectureFramework<br />“Enables, but not restricts, in the implementation of an application following any given architecture”<br />
  25. 25. Swiz in a nutshell<br />Dependency Injection<br />Event Mediation<br />Utilities<br />ServiceHelper<br />Global exception handler<br />And more…<br />MetaData processors<br />
  26. 26. DependencyInjection 1<br />How can a given object obtain a reference to another object?<br />
  27. 27. DependencyInjection 2<br />Object A<br />Object B<br />Depends on<br />
  28. 28. DependencyInjection 3<br />Object A<br />DI framework<br />Object B<br />Object A<br />Object B<br />Application<br />Context<br />
  29. 29. Dependencyinjection 4<br />[Inject]<br />public var userController:UserController;<br /><?xml version="1.0" encoding="utf-8"?><br /><swiz:BeanProvider<br /> <controller:UserController/><br /></swiz:BeanProvider><br />
  30. 30. Dependencyinjection 5<br />Typically inject by type<br />Specify Bean ID if necessary<br />Works with interfaces and inheritance<br />
  31. 31. WhyDependencyInjection?<br />Removes dependencies on concrete implementations<br />No ServiceLocator<br />Easy to see dependencies<br />
  32. 32. EventMediation<br />dispatcher.dispatchEvent(<br />new TaskEvent(TaskEvent.SAVE_TASK_SUCCESS, true));<br />[Mediate(event="TaskEvent.SAVE_TASK_SUCCESS")]<br />publicfunction saveTaskSuccess():void {<br /> this.closeTaskDetailsWindow();<br /> taskController.retrieveTasks();<br />}<br />
  33. 33. EventMediation<br />[Mediate(event="UserWindow.SAVE_CLICKED", properties="user")]<br />public function saveUser(user:User):void {<br /> userController.addUser(user);<br />}<br />
  34. 34. ServiceHelper<br />serviceHelper.executeServiceCall(<br />taskService.addTask(task), <br />onAddTaskResult,<br /> [task]<br />);<br /><swiz:SwizConfigid="mySwizConfig"<br />eventPackages="nl.qnh.addressbook.event"<br />viewPackages="nl.qnh.addressbook.view"<br />defaultFaultHandler="{genericFault}"/><br />
  35. 35. MockDelegateHelper<br />var result:XML = <br /> <tasks><br /> <task><br /> <id>1</id><br /> <name>This is a task</name><br /> </task><br /> </tasks><br />return<br />new MockDelegateHelper().createMockResult(result);<br />
  36. 36. MetaData Processors<br />Easily create your own metadata tags<br />[Log]<br />publicvar log:ILogger;<br />/** Code Omitted **/<br />log.error(“An error occured”);<br />[MediateView(“PersonView”)]<br />public var personView:PersonView;<br />
  37. 37. MetaData Processors<br />Extend BaseMetadataProcessor<br />Implement setUpMetadataTag and tearDownMetadataTag<br />Add “-keep-as3-metadata+=Log” to compiler arguments<br />
  38. 38.
  39. 39. References<br />http://swizframework.org/<br />http://martinfowler.com/eaaDev/uiArchs.html<br />http://blogs.adobe.com/paulw/archives/2007/09/presentation_pa.html<br />

×