Whoops! Where did my architecture go?Approaches to architecture management for Java and Spring applicationsOliver Gierke© ...
Oliver Gierke                                                                                        Spring Data          ...
Background                                 Few years of consulting                                  Lots of code reviews  ...
Roadmap                                         Architecture 101                                     A Java packages model...
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 permi...
Granularity                                                          Modules                                              ...
Granularity                                                        Java ARchive                                           ...
Of layers                                  and slices…© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute wi...
Slice A                  Slice B         Slice C                   Layer 1                  Layer 2                  Layer...
Layers                                    Well understood                                 Known to developers             ...
Slices                                             Hardly understood                                             New to de...
Slice A                  Slice B         Slice C                   Layer 1                  Layer 2                  Layer...
"                      How to implement                                  an architecture                                  ...
Architecture                                VS.                             Codebase© 2011 SpringOne 2GX 2011. All rights ...
"                      How to implement                                  an architecture                                  ...
"                      How to enforce                                  an architecture                                  in...
Code analysis                                                                 JDepend                                     ...
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 di...
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...
….${layer}.${slice}             VS.     ….${slice}.${layer}© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribu...
Layers first                          Leaks slice internals                     Lower layers visible to everyone© 2011 Spri...
"                      Start with less                                  packages and the                                  ...
Slice A                  Slice B         Slice C                   Layer 1                  Layer 2                  Layer...
Slice A                  Slice B         Slice C                   Layer 1                  Layer 2                  Layer...
Slices first                 Start with package per slice             Expose interfaces and domain types                Kee...
Slices first                        Encapsulates business module                         Internals understood anyway© 2011 ...
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 20...
"                      The smallest                                  plugin system                                  ever!©...
Host                          SPI                                              SPI              SPI                       ...
Context                                      No OSGi                                    Spring based                      ...
App                                     Plugin                                             Plugin                         ...
"                      How to make the                                  host aware of the                                 ...
"                      How to dynami-                                  cally collect Spring                               ...
classpath*:META-INF/       spring/plugin-context.xml© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute with...
classpath*:META-INF/                                       spring/plugin-context.xml                          SPI         ...
@Component public class MyComponentImpl implements TransferService {      private List<MyPlugin> plugins;      @Autowired ...
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 ...
(XML?)                           Back in the days                    Probably not a big deal anymore© 2011 SpringOne 2GX 2...
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 ...
@Component public class MyComponentImpl implements TransferService {      // Constructor omitted      public Result myMeth...
Plugins                              Selection criterion                               Callback method                    ...
Registry                                   Equipped with plugins                                  Common access patterns© ...
public interface Plugin<T> {      public boolean supports(T delimiter ); } public interface PluginRegistry<S extends Plugi...
@Component public class MyComponentImpl implements TransferService {      private PluginRegistry<MyPlugin, String> plugins...
@Component public class MyComponentImpl implements TransferService {   private final MyPlugin defaultPlugin = new MyDefault...
OrderAware                                 PluginRegistry                               Respects @Order/Ordered           ...
Bells‘n‘whistles                                                 FactoryBean                                              ...
Hera© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Hera                                         http://hera.synyx.org                                              Apache 2.0...
Spring                               Integration 2© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute withou...
<bean class="….FirstSamplePlugin" /> <bean class="….SecondSamplePlugin" /> <int:channel id="input" /> <int:channel id="out...
Demo© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Take-aways                             Know your dependencies                               On every granularity          ...
Thanks & credits                               Eoin Woods - Talk @ InfoQ© 2011 SpringOne 2GX 2011. All rights reserved. Do...
Resources                                        Sourcecode @ GitHub                                             Sonargrap...
Upcoming SlideShare
Loading in...5
×

Whoops! Where did my architecture go?

1,240

Published on

Slides of my SpringOne 2011 talk on how to implement and enforce architecture in codebases.

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,240
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Whoops! Where did my architecture go?

  1. 1. Whoops! Where did my architecture go?Approaches to architecture management for Java and Spring applicationsOliver Gierke© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  2. 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. 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. 4. Roadmap Architecture 101 A Java packages model Hera© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  5. 5. Architecture 101© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  6. 6. Know your dependencies© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  7. 7. Granularity Modules Layers Vertical slices Subsystems© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  8. 8. Granularity Java ARchive Package Class© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  9. 9. Of layers and slices…© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  10. 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. 11. Layers Well understood Known to developers Less important to business© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  12. 12. Slices Hardly understood New to developers Key for business req© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  13. 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. 14. " How to implement an architecture inside a codebase?© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  15. 15. Architecture VS. Codebase© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  16. 16. " How to implement an architecture inside a codebase?© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  17. 17. " How to enforce an architecture inside a codebase?© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  18. 18. Code analysis JDepend Sonar© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  19. 19. Demo© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  20. 20. Sonargraph Formerly known as SonarJ© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  21. 21. Demo© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  22. 22. A plain Java based approach© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  23. 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. 24. ….${layer}.${slice} VS. ….${slice}.${layer}© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  25. 25. Layers first Leaks slice internals Lower layers visible to everyone© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  26. 26. " Start with less packages and the least visibility possible…© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  27. 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. 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. 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. 30. Slices first Encapsulates business module Internals understood anyway© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  31. 31. Subsystems© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  32. 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. 33. " The smallest plugin system ever!© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  34. 34. Host SPI SPI SPI Plugin Plugin© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  35. 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. 36. App Plugin Plugin Host© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  37. 37. " How to make the host aware of the plugins?© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  38. 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. 39. classpath*:META-INF/ spring/plugin-context.xml© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  40. 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. 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. 42. Demo© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  43. 43. XML? Back in the days© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  44. 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. 45. Easy access?© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  46. 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. 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. 48. Plugins Selection criterion Callback method Let the implementation decide© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  49. 49. Registry Equipped with plugins Common access patterns© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  50. 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. 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. 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. 53. OrderAware PluginRegistry Respects @Order/Ordered OAPR.reverse()© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  54. 54. Bells‘n‘whistles FactoryBean Spring namespace Lazy-eval© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  55. 55. Hera© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  56. 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. 57. Spring Integration 2© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  58. 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. 59. Demo© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  60. 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. 61. Thanks & credits Eoin Woods - Talk @ InfoQ© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  62. 62. Resources Sourcecode @ GitHub Sonargraph© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  1. A particular slide catching your eye?

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

×