Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Framework-agnostic Code - A story about business and code

Framework-agnostic Code - A story about business and code

In this talk, I covered some software architecture concepts in order to make more scalable and reusable application code avoiding coupling with framework tools.

Presented at PHP Conference 2018.

Lucas Mendes

December 07, 2018
Tweet

More Decks by Lucas Mendes

Other Decks in Programming

Transcript

  1. Framework-agnostic Code A story about business and code Lucas Mendes

    
 Product Owner at Tienda Nube Find me: @devsdmf
  2. “Someone who is not able to commit to an opinion

    about something that does not know”
  3. “Software Design is the process by which an agent creates

    an specification of a software artifact, intended to accomplish goals, using a set of primitive components and subject to constraints.” - Wikipedia
  4. “Software architecture refers to the high level structures of a

    software system, the discipline of creating such structures, and the documentation of these structures.” - Wikipedia
  5. Why Components? • Components are reusable • Components are extensible

    • Components are scalable • Components are testable • And we reduce the side-effects when another part of the application changes
  6. –Vaughn Vernon “Developing software that delivers true business value is

    not the same as developing ordinary business software. Software that delivers true business value aligns with the business strategic initiatives.”
  7. An e-commerce platform should… • Have products • Manage the

    stock of these products • Allow customers to buy something • Generate an order • Receive payments • Ship the orders • And so many other business rules
  8. Domains in an e-commerce platform • Customers • Orders •

    Shipping • Payment • Catalog • Discount Coupons • etc…
  9. You can pay for… • A Product • A Service

    • A Ticket • A Donation • etc…
  10. You can pay with… • Credit card (Visa, Mastercard, Amex,

    Diners, …) • Debit card (Visa Electron, Mastercard, Elo, …) • EFT (Thousands of banks) • Ticket (Thousands of issuers) • Cryptocurrencies Exchange (Bitcoin, …) • etc…
  11. In Payments, you can pay through… • PayPal • Stripe

    • Wirecard • PagSeguro • Mercado Pago • etc…
  12. Single Responsibility • A Payment Type • A Payment Method

    • A Payment Gateway • A Payment Request • A Payment Result • etc…
  13. Open/Closed Principle • PagSeguro has 2 different implementation models: Standard

    and Transparent. • A PagSeguro class that implements the Standard checkout. • I should be able to extend the PagSeguro class in order to implement the Transparent behaviour.
  14. Liskov Substitution Principle • The Payment Processor should be able

    to process payments for orders, services, tickets, or anything payable. • The Payment Processor also should be able to work with the PagSeguro class as well with the PagSeguro Transparent class. • And the Payment Gateway should be able to process payments through different payment methods, if it supports.
  15. Interface Segregation • Each Payment Gateway has specific requirements like

    authentication, supported payment methods, installments, taxes, etc… • You should define these behaviours using client-specific interfaces, like Authenticable Interface, Installments Interface, Offline Interface, Transparent, Interface, etc…
  16. Dependency Inversion • One should “depends upon abstractions, not concretions”.

    • A Payment Processor must expect an implementation of a Gateway Interface instead of an instance of a PagSeguro class. • A Payment Processor must expect a Payable Interface instead of an instance of an Order class. • Use Dependency Injection of the abstractions. • Use DI containers to care about the concretion of these abstractions
  17. Facades and Services • Write the whole framework-specific code as

    Facades and Services • Inject and integrate it with the framework using tools like Dependency Injection Container, Service Container, etc… • If you need/want to move away from your current framework, you only need to change the service that integrates your business component with the framework.