Cotton Crop Water Use Craig W. Bednarz University of Georgia, Tifton
Clean Architecture by Andrzej Bednarz
-
Upload
networkedassets -
Category
Leadership & Management
-
view
165 -
download
2
Transcript of Clean Architecture by Andrzej Bednarz
@bednarz_andrzej#DevoxxPL
Platinum Sponsors:
Clean architecture
Andrzej Bednarz
@bednarz_andrzej#DevoxxPL
About me
Img src: https://crisismapper.wordpress.com/2012/08/20/agile-development-manifesto-for-ict4d-projects/
@bednarz_andrzej#DevoxxPL
A new project
Image courtesy of adamr at FreeDigitalPhotos.net
@bednarz_andrzej#DevoxxPL
Main guidelines
Image src: http://www.dlr.de/en/desktopdefault.aspx/tabid-78/7420_read-14264/
Fast development No fear to change
Image courtesy of dan at FreeDigitalPhotos.net
@bednarz_andrzej#DevoxxPL
Clean architecture – principles by UB• The only way to go
fast is to go well
• Architecture is not about tools or frameworks instead it screams intended usage
• It allows to defer/change decisions about UI,
DB, DI, frameworks
• It’s decoupled - aka Hexagonal Architecture, Plugin Architecture
• It’s testable (TDD)
• See Uncle Bob’s presentation online
@bednarz_andrzej#DevoxxPL
Screaming architecture
Top level visibility:modules & functionalitiesframeworks and tools e.g. Spring MVC,
Akka
Img src: https://www.flickr.com/photos/juhansonin/2147259806
@bednarz_andrzej#DevoxxPL
Demo
@bednarz_andrzej#DevoxxPL
Clean architecture – schema
@bednarz_andrzej#DevoxxPL
Application core
Source: Uncle Bob, http://blog.8thlight.com/uncle-bob/2011/11/22/Clean-Architecture.html
@bednarz_andrzej#DevoxxPL
Interactor = use case
Source: Uncle Bob, http://blog.8thlight.com/uncle-bob/2011/11/22/Clean-Architecture.html
@bednarz_andrzej#DevoxxPL
How do we call an interactor?
Source: Uncle Bob, http://blog.8thlight.com/uncle-bob/2011/11/22/Clean-Architecture.html
@bednarz_andrzej#DevoxxPL
How do we return results?
Source: Uncle Bob, http://blog.8thlight.com/uncle-bob/2011/11/22/Clean-Architecture.html
@bednarz_andrzej#DevoxxPL
How do we call infrastructure services?
Source: Uncle Bob, http://blog.8thlight.com/uncle-bob/2011/11/22/Clean-Architecture.html
@bednarz_andrzej#DevoxxPL
All pieces together
Source: Uncle Bob, http://blog.8thlight.com/uncle-bob/2011/11/22/Clean-Architecture.html
@bednarz_andrzej#DevoxxPL
Demo
@bednarz_andrzej#DevoxxPL
Layers?
@bednarz_andrzej#DevoxxPL
Traditional layered architecture
@bednarz_andrzej#DevoxxPL
Layers in clean architecture
@bednarz_andrzej#DevoxxPL
Source: Uncle Bob, http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
@bednarz_andrzej#DevoxxPL
Summary & discussion
@bednarz_andrzej#DevoxxPL
• Lots of additional code: classes and interfaces
• DTOs and conversions
• Cost ...
The Dark Side
Img src: Uncle Bob, http://blog.8thlight.com/uncle-bob/2011/11/22/Clean-Architecture.html
@bednarz_andrzej#DevoxxPL
Cost – example with Rails controller
Source: David Heinemeier Hansson - DHH, https://gist.github.com/dhh/4849a20d2ba89b34b201Based on: Jim Weirich's "Decoupling from Rails"
@bednarz_andrzej#DevoxxPL
Cost – example with Rails controller
Source: David Heinemeier Hansson - DHH, https://gist.github.com/dhh/4849a20d2ba89b34b201Based on: Jim Weirich's "Decoupling from Rails"
@bednarz_andrzej#DevoxxPL
• „Coding an app in Rails is always fun...
for the first 3 months”
• „After some time, small, little things show up. Thin controllers are not really so thin anymore. The tests are no longer below 1 minute.”
Troubles with the Rails way
Source: Andrzej Krzywda, http://rails-refactoring.com/, http://blog.jetbrains.com/ruby/2015/03/interview-with-andrzej-krzywda/
@bednarz_andrzej#DevoxxPL
Excellent testability• Every component
and layer could be tested in isolation.
• Tests are fast and precise.
Clean arch – good sides
No fear to change
@bednarz_andrzej#DevoxxPL
Easy to understand• Explicit by design
• Clearly defined separation of concerns
• Full control of frameworks and tools
Clean arch – good sides
FAST development
HighMaintainability
&Flexibility
with tests
@bednarz_andrzej#DevoxxPL
• Our way• model mapper, generic
classes, lombok
• Uncle Bob’s suggestion• Another (isolated)
boundary for DTO
• Greg Young’s
suggestion• CQRS
But DTOs and conversions - still pain
Img src: https://www.microsoftpressstore.com/articles/article.aspx?p=2248809
@bednarz_andrzej#DevoxxPL
Think, what is fast and clean for you
Img src: https://thesunnyseason.files.wordpress.com/2015/01/closet-before-and-after-1024x781.jpg
@bednarz_andrzej#DevoxxPL
Not new
Not only Java related
Not rocket science
Not home-grown
@bednarz_andrzej#DevoxxPL
• http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
• http://blog.8thlight.com/uncle-bob/2011/11/22/Clean-Architecture.html
• http://blog.8thlight.com/uncle-bob/2011/09/30/Screaming-Architecture.html
• http://alistair.cockburn.us/Hexagonal+architecture
• http://www.growing-object-oriented-software.com/
• http://jeffreypalermo.com/blog/the-onion-architecture-part-1/
• http://martinfowler.com/articles/is-tdd-dead/
• https://groups.google.com/forum/#!forum/clean-code-discussion
• http://en.wikipedia.org/wiki/Data,_context_and_interaction
• http://andrzejonsoftware.blogspot.com/2013/12/the-four-architectures-that-will.html
• Object Oriented Software Engineering: A Use Case Driven Approach, Ivar Jacobson, 1992
References
@bednarz_andrzej#DevoxxPL
• My project on GitHub: https://github.com/andbed/clean-architecture
• http://obvious.retromocha.com/
• https://github.com/michelchenrich/crudrefactorkata.git
• https://github.com/lukasz-duda/ArchitectureSample
• http://www.whitewashing.de/2012/08/13/oop_business_applications_entity_boundary_interactor.html
Examples
@bednarz_andrzej#DevoxxPL
Thank you!
Questions?