SlideShare a Scribd company logo
1 of 62
Download to read offline
Whoops! Where did my architecture go?
Approaches to architecture management for Java and Spring applications



Oliver Gierke




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Oliver Gierke

                                                                                        Spring Data
                                                                                        Core/JPA/MongoDB

                                                                                        ogierke@vmware.com
                                                                                        www.olivergierke.de
                                                                                        olivergierke


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Background
                                 Few years of consulting
                                  Lots of code reviews
                                Eoin Woods‘ talk on InfoQ



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Roadmap
                                         Architecture 101
                                     A Java packages model
                                              Hera



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Architecture 101


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Know your
                      dependencies

© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Granularity
                                                          Modules
                                                           Layers
                                                        Vertical slices
                                                         Subsystems


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Granularity
                                                        Java ARchive
                                                          Package
                                                            Class



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Of layers
                                  and slices…

© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Slice A                  Slice B         Slice C


                   Layer 1



                  Layer 2



                  Layer 3



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Layers
                                    Well understood
                                 Known to developers
                               Less important to business



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Slices
                                             Hardly understood
                                             New to developers
                                            Key for business req



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Slice A                  Slice B         Slice C


                   Layer 1



                  Layer 2



                  Layer 3



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
"                      How to implement
                                  an architecture
                                  inside a codebase?


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Architecture
                                VS.
                             Codebase

© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
"                      How to implement
                                  an architecture
                                  inside a codebase?


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
"                      How to enforce
                                  an architecture
                                  inside a codebase?


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Code analysis
                                                                 JDepend
                                                                  Sonar




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Demo


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Sonargraph
                               Formerly known as SonarJ




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Demo


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
A plain Java
            based approach

© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Slice A                  Slice B         Slice C


                   Layer 1



                  Layer 2



                  Layer 3



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
….${layer}.${slice}
             VS.
     ….${slice}.${layer}

© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Layers first
                          Leaks slice internals
                     Lower layers visible to everyone




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
"                      Start with less
                                  packages and the
                                  least visibility
                                  possible…

© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Slice A                  Slice B         Slice C


                   Layer 1



                  Layer 2



                  Layer 3



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Slice A                  Slice B         Slice C


                   Layer 1



                  Layer 2



                  Layer 3



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Slices first
                 Start with package per slice
             Expose interfaces and domain types
                Keep implementations private



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Slices first
                        Encapsulates business module
                         Internals understood anyway




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Subsystems


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Background
          Risk mgmt. at German public bank
         Quite a few other SpringSource clients




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
"                      The smallest
                                  plugin system
                                  ever!


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Host

                          SPI                                              SPI              SPI



                                  Plugin                                                Plugin


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Context
                                      No OSGi
                                    Spring based
                              Build-time composition
                            Don‘t touch the host system


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
App

                                     Plugin                                             Plugin


                                                                       Host


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
"                      How to make the
                                  host aware of the
                                  plugins?


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
"                      How to dynami-
                                  cally collect Spring
                                  beans of a given
                                  type?

© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
classpath*:META-INF/
       spring/plugin-context.xml




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
classpath*:META-INF/
                                       spring/plugin-context.xml

                          SPI                                              SPI                      SPI


                           META-INF/spring/                                             META-INF/spring/
                           plugin-context.xml                                           plugin-context.xml




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
@Component
 public class MyComponentImpl implements TransferService {

      private List<MyPlugin> plugins;

      @Autowired
      public MyComponentImpl(List<MyPlugin> plugins) {
        this.plugins = plugins;
      }
      …
 }

 public interface MyPlugin {
   void doSomething();
 }



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Demo


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
XML?
                                                   Back in the days




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
(XML?)
                           Back in the days
                    Probably not a big deal anymore




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Easy access?


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
@Component
 public class MyComponentImpl implements TransferService {

      private List<MyPlugin> plugins;

      @Autowired
      public MyComponentImpl(List<MyPlugin> plugins) {
        this.plugins = plugins;
      }
      …
 }

 public interface MyPlugin {
   void doSomething();
 }



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
@Component
 public class MyComponentImpl implements TransferService {

      // Constructor omitted

      public Result myMethod(SomeParameter parameter) {

           // Select the first one to match to invoke?
           // Select multiple ones to invoke?
           // Select and fallback to one if none found?
           // Select and throw an exception if none found?
      }
 }




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Plugins
                              Selection criterion
                               Callback method
                        Let the implementation decide



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Registry
                                   Equipped with plugins
                                  Common access patterns




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
public interface Plugin<T> {

      public boolean supports(T delimiter );
 }


 public interface PluginRegistry<S extends Plugin<T>, T> {

      T getPluginFor(S delimiter);
      T getPluginFor(S delimiter, T default);
      <E extends Exception> T getPluginFor(S del, E exception) throws E;

      List<T> getPluginsFor(S delimiter);
      …
 }



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
@Component
 public class MyComponentImpl implements TransferService {

      private PluginRegistry<MyPlugin, String> plugins;

      @Autowired
      public MyComponentImpl(PluginRegistry<MyPlugin, String> plugins) {
        this.plugins = plugins;
      }
      …
 }

 public interface MyPlugin extends Plugin<String> {
   void doSomething();
 }



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
@Component
 public class MyComponentImpl implements TransferService {
   private final MyPlugin defaultPlugin = new MyDefaultPlugin();

      public Result myMethod(String parameter) {
        // Select the first one to match to invoke?
        … = plugins.getPluginFor(parameter);
        // Select multiple ones to invoke?
        … = plugins.getPluginsFor(parameter);
        // Select and fallback to one if none found?
        … = plugins.getPluginFor(parameter, defaultPlugin);
        // Select and throw an exception if none found?
        … = plugins.getPluginsFor(parameter, new RuntimeException());
      }
 }



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
OrderAware
                                 PluginRegistry
                               Respects @Order/Ordered
                                    OAPR.reverse()




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Bells‘n‘whistles
                                                 FactoryBean
                                               Spring namespace
                                                   Lazy-eval



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Hera


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Hera
                                         http://hera.synyx.org
                                              Apache 2.0
                                         Soon to be on GitHub



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Spring
                               Integration 2



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
<bean class="….FirstSamplePlugin" />
 <bean class="….SecondSamplePlugin" />

 <int:channel id="input" />
 <int:channel id="output" />

 <int-hera:dynamic-service-activator
   input-channel="input"
   outputChannel="output"
   plugin-type= "….MyPlugin"
   method= "myBusinessMethod"
   delimiter="payload"
   invocation-arguments= "payload" />




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Demo


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Take-aways
                             Know your dependencies
                               On every granularity
                             Start as strict as possible
                            Get lenient where necessary


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Thanks & credits
                               Eoin Woods - Talk @ InfoQ




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Resources
                                        Sourcecode @ GitHub
                                             Sonargraph




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.

More Related Content

Viewers also liked

Real world dependency injection - DPC10
Real world dependency injection - DPC10Real world dependency injection - DPC10
Real world dependency injection - DPC10
Stephan Hochdörfer
 
Data Access 2.0? Please welcome, Spring Data!
Data Access 2.0? Please welcome, Spring Data!Data Access 2.0? Please welcome, Spring Data!
Data Access 2.0? Please welcome, Spring Data!
Oliver Gierke
 

Viewers also liked (13)

Sophisticated JPA with Spring & Hades
Sophisticated JPA with Spring & HadesSophisticated JPA with Spring & Hades
Sophisticated JPA with Spring & Hades
 
Spring Roo 1.0.0 Technical Deep Dive
Spring Roo 1.0.0 Technical Deep DiveSpring Roo 1.0.0 Technical Deep Dive
Spring Roo 1.0.0 Technical Deep Dive
 
Mylyn - Increasing developer productivity
Mylyn - Increasing developer productivityMylyn - Increasing developer productivity
Mylyn - Increasing developer productivity
 
Generic DAOs With Hades
Generic DAOs With HadesGeneric DAOs With Hades
Generic DAOs With Hades
 
Mylyn
MylynMylyn
Mylyn
 
Real world dependency injection - DPC10
Real world dependency injection - DPC10Real world dependency injection - DPC10
Real world dependency injection - DPC10
 
Spring in action - Hades & Spring Roo
Spring in action - Hades & Spring RooSpring in action - Hades & Spring Roo
Spring in action - Hades & Spring Roo
 
Data Access 2.0? Please welcome, Spring Data!
Data Access 2.0? Please welcome, Spring Data!Data Access 2.0? Please welcome, Spring Data!
Data Access 2.0? Please welcome, Spring Data!
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
 
Spring integration
Spring integrationSpring integration
Spring integration
 
Spring Data JPA - Repositories done right
Spring Data JPA - Repositories done rightSpring Data JPA - Repositories done right
Spring Data JPA - Repositories done right
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
 
Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Whoops! Where did my architecture go?
Whoops! Where did my architecture go?
 

Similar to Whoops! Where did my architecture go?

Shoretel brilliantly simple_overview
Shoretel brilliantly simple_overviewShoretel brilliantly simple_overview
Shoretel brilliantly simple_overview
Chuck Brown
 
スマートフォン対策ビジネスセミナー / Session1:Adobe AIRで実現する超生産的スマートフォンアプリ開発
スマートフォン対策ビジネスセミナー / Session1:Adobe AIRで実現する超生産的スマートフォンアプリ開発スマートフォン対策ビジネスセミナー / Session1:Adobe AIRで実現する超生産的スマートフォンアプリ開発
スマートフォン対策ビジネスセミナー / Session1:Adobe AIRで実現する超生産的スマートフォンアプリ開発
Nishiyama Shoichi
 
Sweet dreams of load testing
Sweet dreams of load testing Sweet dreams of load testing
Sweet dreams of load testing
Oleg Tatarchuk
 
Using Google Analytics with jQuery Mobile
Using Google Analytics with jQuery MobileUsing Google Analytics with jQuery Mobile
Using Google Analytics with jQuery Mobile
Koji Ishimoto
 
Opening opensource : The Jenkins Way
Opening opensource : The Jenkins WayOpening opensource : The Jenkins Way
Opening opensource : The Jenkins Way
Nicolas De Loof
 
SharePoint2010Integration
SharePoint2010IntegrationSharePoint2010Integration
SharePoint2010Integration
Slava Gorbunov
 
360iDev OTA Distribution and Build Automation
360iDev OTA Distribution and Build Automation360iDev OTA Distribution and Build Automation
360iDev OTA Distribution and Build Automation
Jay Graves
 

Similar to Whoops! Where did my architecture go? (20)

An Introduction to Spring Data
An Introduction to Spring DataAn Introduction to Spring Data
An Introduction to Spring Data
 
Flash camp portugal - Let's talk about Flex baby
Flash camp portugal - Let's talk about Flex babyFlash camp portugal - Let's talk about Flex baby
Flash camp portugal - Let's talk about Flex baby
 
Shoretel brilliantly simple_overview
Shoretel brilliantly simple_overviewShoretel brilliantly simple_overview
Shoretel brilliantly simple_overview
 
Montpellier - Flex UG
Montpellier - Flex UGMontpellier - Flex UG
Montpellier - Flex UG
 
Project Controls Expo, 13th Nov 2013 - "Integrated Project Planning/Schedulin...
Project Controls Expo, 13th Nov 2013 - "Integrated Project Planning/Schedulin...Project Controls Expo, 13th Nov 2013 - "Integrated Project Planning/Schedulin...
Project Controls Expo, 13th Nov 2013 - "Integrated Project Planning/Schedulin...
 
Converge SE 2011 Building a Strong Foundation
Converge SE 2011 Building a Strong FoundationConverge SE 2011 Building a Strong Foundation
Converge SE 2011 Building a Strong Foundation
 
Flex presentation for Paris Android User group PAUG
Flex presentation for Paris Android User group PAUGFlex presentation for Paris Android User group PAUG
Flex presentation for Paris Android User group PAUG
 
Flexpaug 111207121300-phpapp01
Flexpaug 111207121300-phpapp01Flexpaug 111207121300-phpapp01
Flexpaug 111207121300-phpapp01
 
スマートフォン対策ビジネスセミナー / Session1:Adobe AIRで実現する超生産的スマートフォンアプリ開発
スマートフォン対策ビジネスセミナー / Session1:Adobe AIRで実現する超生産的スマートフォンアプリ開発スマートフォン対策ビジネスセミナー / Session1:Adobe AIRで実現する超生産的スマートフォンアプリ開発
スマートフォン対策ビジネスセミナー / Session1:Adobe AIRで実現する超生産的スマートフォンアプリ開発
 
Sweet dreams of load testing
Sweet dreams of load testing Sweet dreams of load testing
Sweet dreams of load testing
 
Oop2012 mobile workshops
Oop2012 mobile workshopsOop2012 mobile workshops
Oop2012 mobile workshops
 
engineering mechanics andrew pytelch 11
engineering mechanics andrew pytelch 11engineering mechanics andrew pytelch 11
engineering mechanics andrew pytelch 11
 
Using Google Analytics with jQuery Mobile
Using Google Analytics with jQuery MobileUsing Google Analytics with jQuery Mobile
Using Google Analytics with jQuery Mobile
 
Jenkins Enterprise by CloudBees Webinar
Jenkins Enterprise by CloudBees WebinarJenkins Enterprise by CloudBees Webinar
Jenkins Enterprise by CloudBees Webinar
 
In The Future We All Use Symfony2
In The Future We All Use Symfony2In The Future We All Use Symfony2
In The Future We All Use Symfony2
 
Opening opensource : The Jenkins Way
Opening opensource : The Jenkins WayOpening opensource : The Jenkins Way
Opening opensource : The Jenkins Way
 
Project Controls Expo, 13th Nov 2013 - "A new visual way to engage executive ...
Project Controls Expo, 13th Nov 2013 - "A new visual way to engage executive ...Project Controls Expo, 13th Nov 2013 - "A new visual way to engage executive ...
Project Controls Expo, 13th Nov 2013 - "A new visual way to engage executive ...
 
Reasons for Flash: Flash Development in an HTML5 and App Store World
Reasons for Flash: Flash Development in an HTML5 and App Store WorldReasons for Flash: Flash Development in an HTML5 and App Store World
Reasons for Flash: Flash Development in an HTML5 and App Store World
 
SharePoint2010Integration
SharePoint2010IntegrationSharePoint2010Integration
SharePoint2010Integration
 
360iDev OTA Distribution and Build Automation
360iDev OTA Distribution and Build Automation360iDev OTA Distribution and Build Automation
360iDev OTA Distribution and Build Automation
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Whoops! Where did my architecture go?

  • 1. Whoops! Where did my architecture go? Approaches to architecture management for Java and Spring applications Oliver Gierke © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 2. Oliver Gierke Spring Data Core/JPA/MongoDB ogierke@vmware.com www.olivergierke.de olivergierke © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 3. Background Few years of consulting Lots of code reviews Eoin Woods‘ talk on InfoQ © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 4. Roadmap Architecture 101 A Java packages model Hera © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 5. Architecture 101 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 6. Know your dependencies © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 7. Granularity Modules Layers Vertical slices Subsystems © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 8. Granularity Java ARchive Package Class © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 9. Of layers and slices… © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 10. Slice A Slice B Slice C Layer 1 Layer 2 Layer 3 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 11. Layers Well understood Known to developers Less important to business © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 12. Slices Hardly understood New to developers Key for business req © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 13. Slice A Slice B Slice C Layer 1 Layer 2 Layer 3 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 14. " How to implement an architecture inside a codebase? © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 15. Architecture VS. Codebase © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 16. " How to implement an architecture inside a codebase? © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 17. " How to enforce an architecture inside a codebase? © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 18. Code analysis JDepend Sonar © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 19. Demo © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 20. Sonargraph Formerly known as SonarJ © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 21. Demo © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 22. A plain Java based approach © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 23. Slice A Slice B Slice C Layer 1 Layer 2 Layer 3 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 24. ….${layer}.${slice} VS. ….${slice}.${layer} © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 25. Layers first Leaks slice internals Lower layers visible to everyone © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 26. " Start with less packages and the least visibility possible… © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 27. Slice A Slice B Slice C Layer 1 Layer 2 Layer 3 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 28. Slice A Slice B Slice C Layer 1 Layer 2 Layer 3 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 29. Slices first Start with package per slice Expose interfaces and domain types Keep implementations private © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 30. Slices first Encapsulates business module Internals understood anyway © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 31. Subsystems © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 32. Background Risk mgmt. at German public bank Quite a few other SpringSource clients © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 33. " The smallest plugin system ever! © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 34. Host SPI SPI SPI Plugin Plugin © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 35. Context No OSGi Spring based Build-time composition Don‘t touch the host system © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 36. App Plugin Plugin Host © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 37. " How to make the host aware of the plugins? © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 38. " How to dynami- cally collect Spring beans of a given type? © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 39. classpath*:META-INF/ spring/plugin-context.xml © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 40. classpath*:META-INF/ spring/plugin-context.xml SPI SPI SPI META-INF/spring/ META-INF/spring/ plugin-context.xml plugin-context.xml © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 41. @Component public class MyComponentImpl implements TransferService { private List<MyPlugin> plugins; @Autowired public MyComponentImpl(List<MyPlugin> plugins) { this.plugins = plugins; } … } public interface MyPlugin { void doSomething(); } © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 42. Demo © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 43. XML? Back in the days © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 44. (XML?) Back in the days Probably not a big deal anymore © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 45. Easy access? © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 46. @Component public class MyComponentImpl implements TransferService { private List<MyPlugin> plugins; @Autowired public MyComponentImpl(List<MyPlugin> plugins) { this.plugins = plugins; } … } public interface MyPlugin { void doSomething(); } © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 47. @Component public class MyComponentImpl implements TransferService { // Constructor omitted public Result myMethod(SomeParameter parameter) { // Select the first one to match to invoke? // Select multiple ones to invoke? // Select and fallback to one if none found? // Select and throw an exception if none found? } } © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 48. Plugins Selection criterion Callback method Let the implementation decide © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 49. Registry Equipped with plugins Common access patterns © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 50. public interface Plugin<T> { public boolean supports(T delimiter ); } public interface PluginRegistry<S extends Plugin<T>, T> { T getPluginFor(S delimiter); T getPluginFor(S delimiter, T default); <E extends Exception> T getPluginFor(S del, E exception) throws E; List<T> getPluginsFor(S delimiter); … } © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 51. @Component public class MyComponentImpl implements TransferService { private PluginRegistry<MyPlugin, String> plugins; @Autowired public MyComponentImpl(PluginRegistry<MyPlugin, String> plugins) { this.plugins = plugins; } … } public interface MyPlugin extends Plugin<String> { void doSomething(); } © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 52. @Component public class MyComponentImpl implements TransferService { private final MyPlugin defaultPlugin = new MyDefaultPlugin(); public Result myMethod(String parameter) { // Select the first one to match to invoke? … = plugins.getPluginFor(parameter); // Select multiple ones to invoke? … = plugins.getPluginsFor(parameter); // Select and fallback to one if none found? … = plugins.getPluginFor(parameter, defaultPlugin); // Select and throw an exception if none found? … = plugins.getPluginsFor(parameter, new RuntimeException()); } } © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 53. OrderAware PluginRegistry Respects @Order/Ordered OAPR.reverse() © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 54. Bells‘n‘whistles FactoryBean Spring namespace Lazy-eval © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 55. Hera © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 56. Hera http://hera.synyx.org Apache 2.0 Soon to be on GitHub © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 57. Spring Integration 2 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 58. <bean class="….FirstSamplePlugin" /> <bean class="….SecondSamplePlugin" /> <int:channel id="input" /> <int:channel id="output" /> <int-hera:dynamic-service-activator input-channel="input" outputChannel="output" plugin-type= "….MyPlugin" method= "myBusinessMethod" delimiter="payload" invocation-arguments= "payload" /> © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 59. Demo © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 60. Take-aways Know your dependencies On every granularity Start as strict as possible Get lenient where necessary © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 61. Thanks & credits Eoin Woods - Talk @ InfoQ © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 62. Resources Sourcecode @ GitHub Sonargraph © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.