Successfully reported this slideshow.
Your SlideShare is downloading. ×

Dependency inversion using ports and adapters

Ad

Dependency Inversion Using
Ports and Adapters
Mahfuzul Haque
@mhaque2012

Ad

Agenda
● The problem
● The idea
● The aims
● Evolution of an existing application
● The concepts
● Show me the code
2

Ad

The problem
Over time core business logic of an application becomes tightly coupled with
various libraries, frameworks and...

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Check these out next

1 of 14 Ad
1 of 14 Ad
Advertisement

More Related Content

Advertisement

Dependency inversion using ports and adapters

  1. 1. Dependency Inversion Using Ports and Adapters Mahfuzul Haque @mhaque2012
  2. 2. Agenda ● The problem ● The idea ● The aims ● Evolution of an existing application ● The concepts ● Show me the code 2
  3. 3. The problem Over time core business logic of an application becomes tightly coupled with various libraries, frameworks and technologies making it harder to evolve and test. Challenges: ● Long lasting product that needs to keep up with changing customer needs and evolution of technology. ● Ability to change core logic confidently with 100% unit test coverage. ● Ability to switch third party codes easily to avoid obsolete code due to technology/vendor lock-down. 3
  4. 4. The idea Ports and Adapters Architecture (Alistair Cockburn) "Allow an application to equally be driven by users, programs, automated test or batch scripts, and to be developed and tested in isolation from its eventual run- time devices and databases." This architecture is also known as: ● Hexagonal Architecture ● Plug-in Architecture 4
  5. 5. The aims ● Decoupling application's core business logic from the services it uses. ● Allowing different services to be plugged in. ● Allowing the application to be run without these services. ● Allowing it to become framework agnostic. 5
  6. 6. An existing application (order processing) Here core business logic is coupled with UI and various libraries, frameworks and technologies: ● Leakage of external libraries and technologies in the core logic by direct dependency. ● Leakage of core logic in the UI which is not reusable in other UI. ● Leakage of the UI into the core logic. 6 Core Application Logic API Controllers Console Commands GUI Controllers Payment Shipping Notification Data Access (ORM)
  7. 7. Evolution using ports and adapters 7 Core Application Logic API Controllers Console Commands GUI Controllers Payment Shipping Notification Data Access (ORM) Primary/Driving Adapters Secondary/Driven Adapters
  8. 8. The concepts ● Core as the central artefact of a system. ● All input and output reaches/leaves the core through a port that isolates the core from external tools, technologies and delivery mechanisms. ● The core should have no knowledge of who/what is sending input or receiving its output. ● This is intended to provide some protection against the evolution of technology. 8
  9. 9. The concepts Primary Port (interface) Primary Adapter Secondary Port (interface) Core Logic Secondary Adapter 9
  10. 10. The concepts (an example) IOrderService API Controller IPaymentService OrderService PaymentService Dependency Dependency 10
  11. 11. Show me the code https://github.com/git-mhaque/demo-ports-and-adapters 11
  12. 12. Q & A 12
  13. 13. References http://wiki.c2.com/?PortsAndAdaptersArchitecture http://wiki.c2.com/?HexagonalArchitecture http://www.dossier-andreas.net/software_architecture/ports_and_adapters.html https://medium.com/the-software-architecture-chronicles/ddd-hexagonal-onion-clean-cqrs-how-i-put-it-all-together-f2590c0aa7f6 https://herbertograca.com/2017/09/14/ports-adapters-architecture/ http://blog.thedigitalgroup.com/understanding-onion-architecture 13
  14. 14. Thank You! 14

×