SlideShare a Scribd company logo
1 of 36
Download to read offline
AMIR BARYLKO
                            DECOUPLING
                                     USING THE

                              EVENT
                            AGGREGATOR

                                 .NET USER GROUP
                                     MAR 2011

Amir Barylko - .NET UG Mar ‘11                     MavenThought Inc.
Wednesday, March 30, 2011
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
RESOURCES

    • Email: amir@barylko.com

    • Twitter: @abarylko

    • Blog: http://www.orthocoders.com

    • Materials: http://www.orthocoders.com/presentations




Amir Barylko - .NET UG Mar ‘11                          MavenThought Inc.
Wednesday, March 30, 2011
INTRO
                                      Coupling
                                      Cohesion
                                    Dependencies
                                 Dependency Injection
                                   IoC Containers


Amir Barylko - .NET UG Mar ‘11                          MavenThought Inc.
Wednesday, March 30, 2011
COUPLING & COHESION




Amir Barylko - .NET UG Mar ‘11    MavenThought Inc.
Wednesday, March 30, 2011
COUPLING
                                  (WIKIPEDIA)



    Degree to which
    each program module relies
    on each one
            of the other modules

Amir Barylko - .NET UG Mar ‘11                  MavenThought Inc.
Wednesday, March 30, 2011
COUPLING II

    Is usually contrasted
                     with cohesion



Amir Barylko - .NET UG Mar ‘11                 MavenThought Inc.
Wednesday, March 30, 2011
COUPLING III

    Invented by Larry Constantine,
    an original developer of
               Structured Design


Amir Barylko - .NET UG Mar ‘11              MavenThought Inc.
Wednesday, March 30, 2011
COUPLING IV

    Low coupling is often a
    sign of a well-structured
    computer system and a
                      good design

Amir Barylko - .NET UG Mar ‘11             MavenThought Inc.
Wednesday, March 30, 2011
COUPLING V

    When combined with
    high cohesion,
    supports high
                  readability and
                  maintainability
Amir Barylko - .NET UG Mar ‘11                MavenThought Inc.
Wednesday, March 30, 2011
COHESION
                                  (WIKIPEDIA)



    measure of how
    strongly-related the
    functionality expressed by the
    source code of a
              software module is
Amir Barylko - .NET UG Mar ‘11                  MavenThought Inc.
Wednesday, March 30, 2011
IS ALL ABOUT
                            DEPENDENCIES




Amir Barylko - .NET UG Mar ‘11              MavenThought Inc.
Wednesday, March 30, 2011
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
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
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
INVERSION OF CONTROL




Amir Barylko - .NET UG Mar ‘11   MavenThought Inc.
Wednesday, March 30, 2011
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
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
REFACTORING
                                   What’s wrong?
                                 Event Aggregator
                                      Demo
                             Desktop &Web applications



Amir Barylko - .NET UG Mar ‘11                           MavenThought Inc.
Wednesday, March 30, 2011
WHAT’S WRONG?




Amir Barylko - .NET UG Mar ‘11              MavenThought Inc.
Wednesday, March 30, 2011
TOO MANY DEPENDENCIES




Amir 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 more services, do I add more
         dependencies to the library?


Amir Barylko - .NET UG Mar ‘11                 MavenThought Inc.
Wednesday, March 30, 2011
DECENTRALIZE

    • Identify boundaries
    • Identify clear responsibilities
    • Reduce complexity
    • Find notification mechanism

Amir Barylko - .NET UG Mar ‘11             MavenThought Inc.
Wednesday, March 30, 2011
WHAT I’D LIKE


                                          Reviews


                    Library        ????

                                              Posters



Amir Barylko - .NET UG Mar ‘11                    MavenThought Inc.
Wednesday, March 30, 2011
EVENT AGGREGATOR




Amir 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
       registration for
       clients
Amir Barylko - .NET UG Mar ‘11            MavenThought Inc.
Wednesday, March 30, 2011
TRAITS

    • Based                 on subject - observer
    • Centralize                 event registration logic
    • No            need to track multiple objects
    • Level                 of indirection


Amir Barylko - .NET UG Mar ‘11                              MavenThought Inc.
Wednesday, March 30, 2011
DEMO




Amir Barylko - .NET UG Mar ‘11          MavenThought Inc.
Wednesday, March 30, 2011
WHAT WE NEED

    •Register                    events
    •Raise                  events
    •Subscribe                    to events

Amir Barylko - .NET UG Mar ‘11                MavenThought Inc.
Wednesday, March 30, 2011
IMPLEMENTATION




Amir Barylko - .NET UG Mar ‘11               MavenThought Inc.
Wednesday, March 30, 2011
WHAT’S NEXT?

    •Show                    movies
    •Add                    notification to show posters
    •Add                    notification to show reviews


Amir Barylko - .NET UG Mar ‘11                       MavenThought Inc.
Wednesday, March 30, 2011
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

    • Source                Code: https://github.com/amirci/decoupling_mar_11




Amir Barylko - .NET UG Mar ‘11                                        MavenThought Inc.
Wednesday, March 30, 2011
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
TDD TRAINING

    • When: May             26 & 27

    • More            info: http://www.maventhought.com

    • Goal: Learn TDD            with real hands on examples




Amir Barylko - .NET UG Mar ‘11                                 MavenThought Inc.
Wednesday, March 30, 2011
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

More Related Content

What's hot

prdc10-Bdd-real-world
prdc10-Bdd-real-worldprdc10-Bdd-real-world
prdc10-Bdd-real-worldAmir Barylko
 
PRDC-ror-trilogy-part1
PRDC-ror-trilogy-part1PRDC-ror-trilogy-part1
PRDC-ror-trilogy-part1Amir Barylko
 
CodeCamp 2012-mvc-vs-ror-2
CodeCamp 2012-mvc-vs-ror-2CodeCamp 2012-mvc-vs-ror-2
CodeCamp 2012-mvc-vs-ror-2Amir Barylko
 
Cpl12 continuous integration
Cpl12 continuous integrationCpl12 continuous integration
Cpl12 continuous integrationAmir Barylko
 
PRDCW-avent-aggregator
PRDCW-avent-aggregatorPRDCW-avent-aggregator
PRDCW-avent-aggregatorAmir Barylko
 

What's hot (7)

prdc10-Bdd-real-world
prdc10-Bdd-real-worldprdc10-Bdd-real-world
prdc10-Bdd-real-world
 
PRDC-ror-trilogy-part1
PRDC-ror-trilogy-part1PRDC-ror-trilogy-part1
PRDC-ror-trilogy-part1
 
CodeCamp 2012-mvc-vs-ror-2
CodeCamp 2012-mvc-vs-ror-2CodeCamp 2012-mvc-vs-ror-2
CodeCamp 2012-mvc-vs-ror-2
 
Cpl12 continuous integration
Cpl12 continuous integrationCpl12 continuous integration
Cpl12 continuous integration
 
PRDCW-avent-aggregator
PRDCW-avent-aggregatorPRDCW-avent-aggregator
PRDCW-avent-aggregator
 
obs-tdd-intro
obs-tdd-introobs-tdd-intro
obs-tdd-intro
 
Capybara1
Capybara1Capybara1
Capybara1
 

More from Amir Barylko

Functional converter project
Functional converter projectFunctional converter project
Functional converter projectAmir Barylko
 
Elm: delightful web development
Elm: delightful web developmentElm: delightful web development
Elm: delightful web developmentAmir Barylko
 
User stories deep dive
User stories deep diveUser stories deep dive
User stories deep diveAmir Barylko
 
Coderetreat hosting training
Coderetreat hosting trainingCoderetreat hosting training
Coderetreat hosting trainingAmir Barylko
 
There's no charge for (functional) awesomeness
There's no charge for (functional) awesomenessThere's no charge for (functional) awesomeness
There's no charge for (functional) awesomenessAmir Barylko
 
What's new in c# 6
What's new in c# 6What's new in c# 6
What's new in c# 6Amir Barylko
 
Who killed object oriented design?
Who killed object oriented design?Who killed object oriented design?
Who killed object oriented design?Amir Barylko
 
From coach to owner - What I learned from the other side
From coach to owner - What I learned from the other sideFrom coach to owner - What I learned from the other side
From coach to owner - What I learned from the other sideAmir Barylko
 
Communication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivityCommunication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivityAmir Barylko
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven DevelopmentAmir Barylko
 
Agile requirements
Agile requirementsAgile requirements
Agile requirementsAmir Barylko
 
Agile teams and responsibilities
Agile teams and responsibilitiesAgile teams and responsibilities
Agile teams and responsibilitiesAmir Barylko
 
Beutiful javascript with coffeescript
Beutiful javascript with coffeescriptBeutiful javascript with coffeescript
Beutiful javascript with coffeescriptAmir Barylko
 
Rich UI with Knockout.js &amp; Coffeescript
Rich UI with Knockout.js &amp; CoffeescriptRich UI with Knockout.js &amp; Coffeescript
Rich UI with Knockout.js &amp; CoffeescriptAmir Barylko
 

More from Amir Barylko (20)

Functional converter project
Functional converter projectFunctional converter project
Functional converter project
 
Elm: delightful web development
Elm: delightful web developmentElm: delightful web development
Elm: delightful web development
 
Dot Net Core
Dot Net CoreDot Net Core
Dot Net Core
 
No estimates
No estimatesNo estimates
No estimates
 
User stories deep dive
User stories deep diveUser stories deep dive
User stories deep dive
 
Coderetreat hosting training
Coderetreat hosting trainingCoderetreat hosting training
Coderetreat hosting training
 
There's no charge for (functional) awesomeness
There's no charge for (functional) awesomenessThere's no charge for (functional) awesomeness
There's no charge for (functional) awesomeness
 
What's new in c# 6
What's new in c# 6What's new in c# 6
What's new in c# 6
 
Productive teams
Productive teamsProductive teams
Productive teams
 
Who killed object oriented design?
Who killed object oriented design?Who killed object oriented design?
Who killed object oriented design?
 
From coach to owner - What I learned from the other side
From coach to owner - What I learned from the other sideFrom coach to owner - What I learned from the other side
From coach to owner - What I learned from the other side
 
Communication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivityCommunication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivity
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven Development
 
Refactoring
RefactoringRefactoring
Refactoring
 
Agile requirements
Agile requirementsAgile requirements
Agile requirements
 
Agile teams and responsibilities
Agile teams and responsibilitiesAgile teams and responsibilities
Agile teams and responsibilities
 
Refactoring
RefactoringRefactoring
Refactoring
 
Beutiful javascript with coffeescript
Beutiful javascript with coffeescriptBeutiful javascript with coffeescript
Beutiful javascript with coffeescript
 
Sass & bootstrap
Sass & bootstrapSass & bootstrap
Sass & bootstrap
 
Rich UI with Knockout.js &amp; Coffeescript
Rich UI with Knockout.js &amp; CoffeescriptRich UI with Knockout.js &amp; Coffeescript
Rich UI with Knockout.js &amp; Coffeescript
 

Recently uploaded

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Recently uploaded (20)

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

decoupling-ea

  • 1. AMIR BARYLKO DECOUPLING USING THE EVENT AGGREGATOR .NET USER GROUP MAR 2011 Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 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. RESOURCES • Email: amir@barylko.com • Twitter: @abarylko • Blog: http://www.orthocoders.com • Materials: http://www.orthocoders.com/presentations Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 4. INTRO Coupling Cohesion Dependencies Dependency Injection IoC Containers Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 5. COUPLING & COHESION Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 6. COUPLING (WIKIPEDIA) Degree to which each program module relies on each one of the other modules Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 7. COUPLING II Is usually contrasted with cohesion Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 8. COUPLING III Invented by Larry Constantine, an original developer of Structured Design Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 9. COUPLING IV Low coupling is often a sign of a well-structured computer system and a good design Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 10. COUPLING V When combined with high cohesion, supports high readability and maintainability Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 11. COHESION (WIKIPEDIA) measure of how strongly-related the functionality expressed by the source code of a software module is Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 12. IS ALL ABOUT DEPENDENCIES Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 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. 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. 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. INVERSION OF CONTROL Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 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. 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. REFACTORING What’s wrong? Event Aggregator Demo Desktop &Web applications Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 20. WHAT’S WRONG? Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 21. TOO MANY DEPENDENCIES Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 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. DECENTRALIZE • Identify boundaries • Identify clear responsibilities • Reduce complexity • Find notification mechanism Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 24. WHAT I’D LIKE Reviews Library ???? Posters Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 25. EVENT AGGREGATOR Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 26. THE PATTERN Channel events from multiple objects into a single object to s i m p l i f y registration for clients Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 27. TRAITS • Based on subject - observer • Centralize event registration logic • No need to track multiple objects • Level of indirection Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 28. DEMO Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 29. WHAT WE NEED •Register events •Raise events •Subscribe to events Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 30. IMPLEMENTATION Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 31. WHAT’S NEXT? •Show movies •Add notification to show posters •Add notification to show reviews Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 32. QUESTIONS? Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 33. RESOURCES • Email: amir@barylko.com • Twitter: @abarylko • Presentation: http://www.orthocoders.com/presentations • Source Code: https://github.com/amirci/decoupling_mar_11 Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 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. TDD TRAINING • When: May 26 & 27 • More info: http://www.maventhought.com • Goal: Learn TDD with real hands on examples Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, March 30, 2011
  • 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