AMIR BARYLKO                            DECOUPLING                                     USING THE                          ...
WHO AM I?    • Quality               Expert    • Architect    • Developer    • Mentor    • Great            cook    • The ...
RESOURCES    • Email: amir@barylko.com    • Twitter: @abarylko    • Blog: http://www.orthocoders.com    • Materials: http:...
INTRO                                      Coupling                                      Cohesion                         ...
COUPLING & COHESIONAmir Barylko - .NET UG Mar ‘11    MavenThought Inc.Wednesday, March 30, 2011
COUPLING                                  (WIKIPEDIA)    Degree to which    each program module relies    on each one     ...
COUPLING II    Is usually contrasted                     with cohesionAmir Barylko - .NET UG Mar ‘11                 Maven...
COUPLING III    Invented by Larry Constantine,    an original developer of               Structured DesignAmir Barylko - ....
COUPLING IV    Low coupling is often a    sign of a well-structured    computer system and a                      good des...
COUPLING V    When combined with    high cohesion,    supports high                  readability and                  main...
COHESION                                  (WIKIPEDIA)    measure of how    strongly-related the    functionality expressed...
IS ALL ABOUT                            DEPENDENCIESAmir Barylko - .NET UG Mar ‘11              MavenThought Inc.Wednesday...
HARDCODED                            DEPENDENCIES    public MovieLibrary()    {        this._storage = new LocalStorage();...
EXTRACT INTERFACES    private JaySherman _critic;    private IMDBPosterService _posterService;    private LocalStorage _st...
DEPENDENCY INJECTION    public MovieLibrary(IMovieStorage storage,                                 IMovieCritic critic,   ...
INVERSION OF CONTROLAmir Barylko - .NET UG Mar ‘11   MavenThought Inc.Wednesday, March 30, 2011
POOR’S MAN DI    public MovieLibrary()    {              this._storage = new LocalStorage();              this._critic = n...
USING IOC CONTAINER    Container.Register(        Component            .For<IMovieCritic>()            .ImplementedBy<JayS...
REFACTORING                                   What’s wrong?                                 Event Aggregator              ...
WHAT’S WRONG?Amir Barylko - .NET UG Mar ‘11              MavenThought Inc.Wednesday, March 30, 2011
TOO MANY DEPENDENCIESAmir Barylko - .NET UG Mar ‘11   MavenThought Inc.Wednesday, March 30, 2011
LET’S THINK    • Why the critic has to know the library (or         viceversa)?    • Or the poster service?    • If I need...
DECENTRALIZE    • Identify boundaries    • Identify clear responsibilities    • Reduce complexity    • Find notification me...
WHAT I’D LIKE                                          Reviews                    Library        ????                     ...
EVENT AGGREGATORAmir Barylko - .NET UG Mar ‘11             MavenThought Inc.Wednesday, March 30, 2011
THE PATTERN       Channel events       from multiple       objects into a       single object to       s i m p l i f y    ...
TRAITS    • Based                 on subject - observer    • Centralize                 event registration logic    • No  ...
DEMOAmir Barylko - .NET UG Mar ‘11          MavenThought Inc.Wednesday, March 30, 2011
WHAT WE NEED    •Register                    events    •Raise                  events    •Subscribe                    to ...
IMPLEMENTATIONAmir Barylko - .NET UG Mar ‘11               MavenThought Inc.Wednesday, March 30, 2011
WHAT’S NEXT?    •Show                    movies    •Add                    notification to show posters    •Add            ...
QUESTIONS?Amir Barylko - .NET UG Mar ‘11                MavenThought Inc.Wednesday, March 30, 2011
RESOURCES    • Email: amir@barylko.com    • Twitter: @abarylko    • Presentation: http://www.orthocoders.com/presentations...
RESOURCES II    •Coupling: http://en.wikipedia.org/wiki/Coupling_(computer_programming)    •Event Aggregator: http://marti...
TDD TRAINING    • When: May             26 & 27    • More            info: http://www.maventhought.com    • Goal: Learn TD...
AGILE USER GROUP    • Check             it out! : http://www.agilewinnipeg.com    • Apr         5: Agile Planning    • May...
Upcoming SlideShare
Loading in...5
×

decoupling-ea

332

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
332
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

decoupling-ea

  1. 1. AMIR BARYLKO DECOUPLING USING THE EVENT AGGREGATOR .NET USER GROUP MAR 2011Amir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  2. 2. WHO AM I? • Quality Expert • Architect • Developer • Mentor • Great cook • The one who’s entertaining you for the next hour!Amir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  3. 3. RESOURCES • Email: amir@barylko.com • Twitter: @abarylko • Blog: http://www.orthocoders.com • Materials: http://www.orthocoders.com/presentationsAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  4. 4. INTRO Coupling Cohesion Dependencies Dependency Injection IoC ContainersAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  5. 5. COUPLING & COHESIONAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  6. 6. COUPLING (WIKIPEDIA) Degree to which each program module relies on each one of the other modulesAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  7. 7. COUPLING II Is usually contrasted with cohesionAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  8. 8. COUPLING III Invented by Larry Constantine, an original developer of Structured DesignAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  9. 9. COUPLING IV Low coupling is often a sign of a well-structured computer system and a good designAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  10. 10. COUPLING V When combined with high cohesion, supports high readability and maintainabilityAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  11. 11. COHESION (WIKIPEDIA) measure of how strongly-related the functionality expressed by the source code of a software module isAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  12. 12. IS ALL ABOUT DEPENDENCIESAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  13. 13. HARDCODED DEPENDENCIES public MovieLibrary() { this._storage = new LocalStorage(); this._critic = new JaySherman(); this._posterService = new IMDBPosterService(); } Impossible to test or maintain!Amir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  14. 14. EXTRACT INTERFACES private JaySherman _critic; private IMDBPosterService _posterService; private LocalStorage _storage; private IMovieCritic _critic; private IMoviePosterService _posterService; private IMovieStorage _storage;Amir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  15. 15. DEPENDENCY INJECTION public MovieLibrary(IMovieStorage storage, IMovieCritic critic, IMoviePosterService posterService) { this._storage = storage; this._critic = critic; this._posterService = posterService; } Better for testing... but who is going to initialize them?Amir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  16. 16. INVERSION OF CONTROLAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  17. 17. POOR’S MAN DI public MovieLibrary() { this._storage = new LocalStorage(); this._critic = new JaySherman(); this._posterService = new IMDBPosterService(); } Still testeable... but smells!Amir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  18. 18. USING IOC CONTAINER Container.Register( Component .For<IMovieCritic>() .ImplementedBy<JaySherman>(), Component .For<IMoviePosterService>() .ImplementedBy<IMDBPosterService>(), Component .For<IMovieStorage>() .ImplementedBy<LocalStorage>());Amir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  19. 19. REFACTORING What’s wrong? Event Aggregator Demo Desktop &Web applicationsAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  20. 20. WHAT’S WRONG?Amir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  21. 21. TOO MANY DEPENDENCIESAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  22. 22. LET’S THINK • Why the critic has to know the library (or viceversa)? • Or the poster service? • If I need more services, do I add more dependencies to the library?Amir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  23. 23. DECENTRALIZE • Identify boundaries • Identify clear responsibilities • Reduce complexity • Find notification mechanismAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  24. 24. WHAT I’D LIKE Reviews Library ???? PostersAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  25. 25. EVENT AGGREGATORAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  26. 26. THE PATTERN Channel events from multiple objects into a single object to s i m p l i f y registration for clientsAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  27. 27. TRAITS • Based on subject - observer • Centralize event registration logic • No need to track multiple objects • Level of indirectionAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  28. 28. DEMOAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  29. 29. WHAT WE NEED •Register events •Raise events •Subscribe to eventsAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  30. 30. IMPLEMENTATIONAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  31. 31. WHAT’S NEXT? •Show movies •Add notification to show posters •Add notification to show reviewsAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  32. 32. QUESTIONS?Amir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  33. 33. RESOURCES • Email: amir@barylko.com • Twitter: @abarylko • Presentation: http://www.orthocoders.com/presentations • Source Code: https://github.com/amirci/decoupling_mar_11Amir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  34. 34. RESOURCES II •Coupling: http://en.wikipedia.org/wiki/Coupling_(computer_programming) •Event Aggregator: http://martinfowler.com/eaaDev/EventAggregator.html MavenThought Commons:https://github.com/amirci/mt_commons •Bootstrapper:http://bootstrapper.codeplex.com/ •Windsor Container:http://www.castleproject.org/container/Amir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  35. 35. TDD TRAINING • When: May 26 & 27 • More info: http://www.maventhought.com • Goal: Learn TDD with real hands on examplesAmir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  36. 36. AGILE USER GROUP • Check it out! : http://www.agilewinnipeg.com • Apr 5: Agile Planning • May: Agile Stories • Jun: Testing?Amir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, March 30, 2011
  1. A particular slide catching your eye?

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

×