SlideShare a Scribd company logo
From class
To architecture
Marcin Hawraniak
About me
● Working @ Red-Sky
● CTO @ ChallengeMe.GG
● 10+ years of commercial programming
● Building stuff to solve problems :)
Disclaimer
● There are no solutions that solve all problems
● Presentation is on abstract level
Developer wants to code a class.
Class is a solution for a problem so Developer
seeks one...
Problem distillation
Source: http://serviceorientation.com/serviceorientation/service_composability
Source: http://serviceorientation.com/serviceorientation/service_composability
Source: http://serviceorientation.com/serviceorientation/the_need_for_service_orientation
Problem distillation
● This is not business layer only, applies to technical aspects as well!
● Business may benefit early due to smaller solutions being ready faster than all at
once
● Communicate with business to find critical ones - focus on them first
What helps to control size of a
problem/solution?
Domain Driven Design
Domain Driven Design
Source: Domain Driven Design Quickly
Source: Domain Driven Design Quickly
DDD - Bounded Context
● Logical barriers of the model that give solution to a problem
● Same entity across Bounded Contexts may have different names and properties
● Bounded Context may be considered as a logical boundary in monolith application or
Microservice
● Helps in non DDD environment too!
Source: “.NET Microservices: Architecture for Containerized .NET Applications”
Use case: Tournaments with schedule
Use case: Tournaments with schedule
● Tournaments should support multiple systems (single/double elimination, swiss, …)
● Matches are scheduled
● Created matches allow to play a game
Tournaments
Scheduled Matches
Use case: Tournaments with schedule
Assumptions:
● Platform already supports matches
Tournaments
Scheduled Matches
Matches
Use case: Tournaments with schedule
Business concerns:
● We may require scheduled matches without tournaments in the future
Tournaments Scheduled Matches Matches
Use case: Tournaments with schedule
Tournaments Scheduled Matches Matches
Tournaments with
scheduled
(business process)
Business process vs lower level components
Business process Lower level components
● Ties components together
● Controls the flow
● Use case naming convention in
code
● Business use case Bounded
Context
● Quite generic/reusable as a
component
● Component specific naming
convention in the code
● Local Bounded Context
Use case: Tournaments with schedule
Benefits
● Easier to split work across developers
● Ready to support new feature
● Reusability of components
● Less code in each component
● Very specific business requirements’ details not spoiling reusable components
All good but...
Time
Scope Quality
Following all principles not always possible
● Chasing perfection - endless refactoring
● “Better working than perfect”
● Almost everyone may give different solution for the same problem
● Write code in such way (decoupling) to limit scope of changes leaking outside of
given code scope while refactoring
● Be aware of what rules are being broken (SOLID)
When there is no time
● Assess price of technical debt and the risk involved
○ Is component critical?
○ Does current state introduces risks?
○ Is the code readable enough?
○ In case of refactoring, will I need to change code only within this single component?
○ How important is it for business?
○ How business will benefit by changing this in comparison to cost of change?
○ Does component follow project’s convention enough?
○ How business would benefit from current code despite its quality?
○ Will I be able to refactor it later?
● Negotiate scope
● Communicate!
Mechanical vs deep refactoring
● Mechanical refactoring usually is cheap and introduces low risk
○ Examples:
■ Renaming Classes / Interfaces
■ Code formatting
● Deep refactoring
○ Requires changing actual domain (may introduce new edge cases)
○ Within single Bounded Context introduces low to medium risk (unit tests)
○ Across many Bounded Contexts introduces medium to high risk (integration test)
Common closure principle
The classes in a package should be closed together against the same kinds of changes.
A change that affects a package affects all the classes in that package.
Source: “Principles of Package Design” by Matthias Noback
Classes grouped using Bounded Context.
Ideas how to structure the code?
Abstract of directory structure
Source: https://fideloper.com/hexagonal-architecture
Source: https://fideloper.com/hexagonal-architecture
Source: https://fideloper.com/hexagonal-architecture
Top directory tree
● Framework
○ Communication related (HTTP, Websocket, CLI, ACL, rate limiting, …)
● Application
○ Connects business logic with framework
○ Implement Domain interfaces (like database, API or other 3rd party libraries)
○ Transactions handling
○ Catches Domain Events (logging, queueing, sending email)
● Domain
○ Completely technology agnostic by using Interfaces
○ Contains Components and Shared Kernel
Component / Business process - example
● Entities
○ Entity1
○ Entity2
● Repositories
○ Entity1RepositoryInterface
○ Entity2RepositoryInterface
● Service
● Tests
Component / Business process - notes
● If Entity1 references lots of Entity2 (oneToMany)
○ Make separate repository for each Entity
○ Foreign keys are ok within Component
● Repositories
○ Generic methods (at least)
○ Performance optimized methods if needed (counting)
● Service
○ Calling methods changes state of Entity
● Tests
○ Unit tests
Component / Business process - notes
● Tracking - each component may track it’s own domain specific history changes
○ Consider tracking more than needed - business will ask soon about KPIs
○ To solve storage/performance issue implementation may use NoSQL
○ Tracking may be explicit (in domain) or implicit (via tracking dispatched events)
● Passing data to service methods
○ Simple types makes testing easier
Shared kernel - notes
● Components commonly used by other Components (Event Dispatcher, Base Entity
Classes, Traits, Scheduler)
● Changes may affect other Components
Components relation to other components
● Assigning Entity reference to Entity from other component
○ In most cases ID is enough (avoid foreign keys)
○ Referencing different kinds of Entities by storing Context Type and Context ID, example:
■ Type Match and Match ID
■ Type Tournament and Tournament ID
Relation on code level vs service level
● Code level
○ Single app instance
○ Higher level components may extend lower level components with plugins
○ Coupled code vs Dispatching Events
● Service level (SOA / Microservices)
○ No code sharing
○ Access only via API / Messaging
Technical components
● Do not mix low level technical components with Domain
● Naming basing on Context:
○ Image processing
○ Communication (Websockets / HTTP / Queue)
○ Domain Framework (ie Interfaces for Commands, Dispatcher)
○ Addition to 3rd party framework (Symfony / Laravel)
CQRS
Command Query Responsibility Segregation
Source: https://microservices.io/patterns/data/cqrs.html
What if I don’t have full CQRS?
● Commands will use Services from domain
● Queries
○ In simplest form may use existing Repositories from Components
○ Consider separate Repository Interface for Commands/Services and Queries
○ Keep adding counters / redundant data step by step avoid complex joins and speed up queries
○ Over time Query Repository may use more advanced solutions
Architectures
Source: https://docs.microsoft.com/en-us/previous-versions/msp-n-p/ee658090(v%3dpandp.10)
Source: http://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html
Source: https://fideloper.com/hexagonal-architecture
Source:
https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexag
onal-onion-clean-cqrs-how-i-put-it-all-together/
My Class
● Is it technical, domain or connecting domain with framework?
● Is it for state change or reading?
● Is it generic or application/use case specific?
● Does it have state?
● Which properties are optimization purposes?
● What Bounded Contexts it should be aware of?
Summary
● Chosen approach depends on team’s experience, available time, project’s lifespan
● Seek for Bounded Context in non DDD components/layers too!
● Coupling within Component is good. Unnecessary coupling between Components is
bad.
● There are no strict rules, each team goes their own path
● Introduce new ideas in your project step by step
● Explore, make mistakes, improve
Resources
● https://www.infoq.com/minibooks/domain-driven-design-quickly
● https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/
● https://fideloper.com/hexagonal-architecture
● http://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html
● https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-i
t-all-together/
Questions?
● hawraniak@red-sky.pl
● Looking for challenges? rekrutacja@red-sky.pl
Thank you <3

More Related Content

Similar to From class to architecture

Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"
Fwdays
 
Clean architecture
Clean architectureClean architecture
Clean architecture
.NET Crowd
 
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
OdessaJS Conf
 
The working architecture of node js applications open tech week javascript ...
The working architecture of node js applications   open tech week javascript ...The working architecture of node js applications   open tech week javascript ...
The working architecture of node js applications open tech week javascript ...
Viktor Turskyi
 
The working architecture of NodeJS applications, Виктор Турский
The working architecture of NodeJS applications, Виктор ТурскийThe working architecture of NodeJS applications, Виктор Турский
The working architecture of NodeJS applications, Виктор Турский
Sigma Software
 
JavaScript for Enterprise Applications
JavaScript for Enterprise ApplicationsJavaScript for Enterprise Applications
JavaScript for Enterprise Applications
Piyush Katariya
 
Baby steps to Domain-Driven Design
Baby steps to Domain-Driven DesignBaby steps to Domain-Driven Design
Baby steps to Domain-Driven Design
Žilvinas Kuusas
 
Keeping business logic out of your UIs
Keeping business logic out of your UIsKeeping business logic out of your UIs
Keeping business logic out of your UIs
Petter Holmström
 
DDD with Behat
DDD with BehatDDD with Behat
DDD with Behat
Anton Serdyuk
 
Not my problem - Delegating responsibility to infrastructure
Not my problem - Delegating responsibility to infrastructureNot my problem - Delegating responsibility to infrastructure
Not my problem - Delegating responsibility to infrastructure
Yshay Yaacobi
 
Microservices as an evolutionary architecture: lessons learned
Microservices as an evolutionary architecture: lessons learnedMicroservices as an evolutionary architecture: lessons learned
Microservices as an evolutionary architecture: lessons learned
Luram Archanjo
 
On component interface
On component interfaceOn component interface
On component interface
Laurence Chen
 
Designing Salesforce Platform Events
Designing Salesforce Platform EventsDesigning Salesforce Platform Events
Designing Salesforce Platform Events
CodeScience
 
Fighting legacy with hexagonal architecture and frameworkless php
Fighting legacy with hexagonal architecture and frameworkless phpFighting legacy with hexagonal architecture and frameworkless php
Fighting legacy with hexagonal architecture and frameworkless php
Fabio Pellegrini
 
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
Codemotion
 
Build Your Own Angular Component Library
Build Your Own Angular Component LibraryBuild Your Own Angular Component Library
Build Your Own Angular Component Library
Carlo Bonamico
 
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
Binary Studio
 
Spring 21 Salesforce Release Webinar
Spring 21 Salesforce Release WebinarSpring 21 Salesforce Release Webinar
Spring 21 Salesforce Release Webinar
brightgenss
 
How to Choose an Integration Platform Vendor for Your Business
How to Choose an Integration Platform Vendor for Your BusinessHow to Choose an Integration Platform Vendor for Your Business
How to Choose an Integration Platform Vendor for Your Business
WSO2
 
Software Architecture - All you need to know
Software Architecture - All you need to knowSoftware Architecture - All you need to know
Software Architecture - All you need to know
Vincent Composieux
 

Similar to From class to architecture (20)

Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
 
The working architecture of node js applications open tech week javascript ...
The working architecture of node js applications   open tech week javascript ...The working architecture of node js applications   open tech week javascript ...
The working architecture of node js applications open tech week javascript ...
 
The working architecture of NodeJS applications, Виктор Турский
The working architecture of NodeJS applications, Виктор ТурскийThe working architecture of NodeJS applications, Виктор Турский
The working architecture of NodeJS applications, Виктор Турский
 
JavaScript for Enterprise Applications
JavaScript for Enterprise ApplicationsJavaScript for Enterprise Applications
JavaScript for Enterprise Applications
 
Baby steps to Domain-Driven Design
Baby steps to Domain-Driven DesignBaby steps to Domain-Driven Design
Baby steps to Domain-Driven Design
 
Keeping business logic out of your UIs
Keeping business logic out of your UIsKeeping business logic out of your UIs
Keeping business logic out of your UIs
 
DDD with Behat
DDD with BehatDDD with Behat
DDD with Behat
 
Not my problem - Delegating responsibility to infrastructure
Not my problem - Delegating responsibility to infrastructureNot my problem - Delegating responsibility to infrastructure
Not my problem - Delegating responsibility to infrastructure
 
Microservices as an evolutionary architecture: lessons learned
Microservices as an evolutionary architecture: lessons learnedMicroservices as an evolutionary architecture: lessons learned
Microservices as an evolutionary architecture: lessons learned
 
On component interface
On component interfaceOn component interface
On component interface
 
Designing Salesforce Platform Events
Designing Salesforce Platform EventsDesigning Salesforce Platform Events
Designing Salesforce Platform Events
 
Fighting legacy with hexagonal architecture and frameworkless php
Fighting legacy with hexagonal architecture and frameworkless phpFighting legacy with hexagonal architecture and frameworkless php
Fighting legacy with hexagonal architecture and frameworkless php
 
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
 
Build Your Own Angular Component Library
Build Your Own Angular Component LibraryBuild Your Own Angular Component Library
Build Your Own Angular Component Library
 
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
 
Spring 21 Salesforce Release Webinar
Spring 21 Salesforce Release WebinarSpring 21 Salesforce Release Webinar
Spring 21 Salesforce Release Webinar
 
How to Choose an Integration Platform Vendor for Your Business
How to Choose an Integration Platform Vendor for Your BusinessHow to Choose an Integration Platform Vendor for Your Business
How to Choose an Integration Platform Vendor for Your Business
 
Software Architecture - All you need to know
Software Architecture - All you need to knowSoftware Architecture - All you need to know
Software Architecture - All you need to know
 

Recently uploaded

A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
GDSC PJATK
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
saastr
 

Recently uploaded (20)

A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
 

From class to architecture

  • 2. About me ● Working @ Red-Sky ● CTO @ ChallengeMe.GG ● 10+ years of commercial programming ● Building stuff to solve problems :)
  • 3. Disclaimer ● There are no solutions that solve all problems ● Presentation is on abstract level
  • 4. Developer wants to code a class. Class is a solution for a problem so Developer seeks one...
  • 9. Problem distillation ● This is not business layer only, applies to technical aspects as well! ● Business may benefit early due to smaller solutions being ready faster than all at once ● Communicate with business to find critical ones - focus on them first
  • 10. What helps to control size of a problem/solution?
  • 12. Domain Driven Design Source: Domain Driven Design Quickly
  • 13. Source: Domain Driven Design Quickly
  • 14. DDD - Bounded Context ● Logical barriers of the model that give solution to a problem ● Same entity across Bounded Contexts may have different names and properties ● Bounded Context may be considered as a logical boundary in monolith application or Microservice ● Helps in non DDD environment too!
  • 15. Source: “.NET Microservices: Architecture for Containerized .NET Applications”
  • 16. Use case: Tournaments with schedule
  • 17. Use case: Tournaments with schedule ● Tournaments should support multiple systems (single/double elimination, swiss, …) ● Matches are scheduled ● Created matches allow to play a game Tournaments Scheduled Matches
  • 18. Use case: Tournaments with schedule Assumptions: ● Platform already supports matches Tournaments Scheduled Matches Matches
  • 19. Use case: Tournaments with schedule Business concerns: ● We may require scheduled matches without tournaments in the future Tournaments Scheduled Matches Matches
  • 20. Use case: Tournaments with schedule Tournaments Scheduled Matches Matches Tournaments with scheduled (business process)
  • 21. Business process vs lower level components Business process Lower level components ● Ties components together ● Controls the flow ● Use case naming convention in code ● Business use case Bounded Context ● Quite generic/reusable as a component ● Component specific naming convention in the code ● Local Bounded Context
  • 22. Use case: Tournaments with schedule Benefits ● Easier to split work across developers ● Ready to support new feature ● Reusability of components ● Less code in each component ● Very specific business requirements’ details not spoiling reusable components
  • 25. Following all principles not always possible ● Chasing perfection - endless refactoring ● “Better working than perfect” ● Almost everyone may give different solution for the same problem ● Write code in such way (decoupling) to limit scope of changes leaking outside of given code scope while refactoring ● Be aware of what rules are being broken (SOLID)
  • 26. When there is no time ● Assess price of technical debt and the risk involved ○ Is component critical? ○ Does current state introduces risks? ○ Is the code readable enough? ○ In case of refactoring, will I need to change code only within this single component? ○ How important is it for business? ○ How business will benefit by changing this in comparison to cost of change? ○ Does component follow project’s convention enough? ○ How business would benefit from current code despite its quality? ○ Will I be able to refactor it later? ● Negotiate scope ● Communicate!
  • 27. Mechanical vs deep refactoring ● Mechanical refactoring usually is cheap and introduces low risk ○ Examples: ■ Renaming Classes / Interfaces ■ Code formatting ● Deep refactoring ○ Requires changing actual domain (may introduce new edge cases) ○ Within single Bounded Context introduces low to medium risk (unit tests) ○ Across many Bounded Contexts introduces medium to high risk (integration test)
  • 28. Common closure principle The classes in a package should be closed together against the same kinds of changes. A change that affects a package affects all the classes in that package. Source: “Principles of Package Design” by Matthias Noback
  • 29. Classes grouped using Bounded Context. Ideas how to structure the code?
  • 34. Top directory tree ● Framework ○ Communication related (HTTP, Websocket, CLI, ACL, rate limiting, …) ● Application ○ Connects business logic with framework ○ Implement Domain interfaces (like database, API or other 3rd party libraries) ○ Transactions handling ○ Catches Domain Events (logging, queueing, sending email) ● Domain ○ Completely technology agnostic by using Interfaces ○ Contains Components and Shared Kernel
  • 35. Component / Business process - example ● Entities ○ Entity1 ○ Entity2 ● Repositories ○ Entity1RepositoryInterface ○ Entity2RepositoryInterface ● Service ● Tests
  • 36. Component / Business process - notes ● If Entity1 references lots of Entity2 (oneToMany) ○ Make separate repository for each Entity ○ Foreign keys are ok within Component ● Repositories ○ Generic methods (at least) ○ Performance optimized methods if needed (counting) ● Service ○ Calling methods changes state of Entity ● Tests ○ Unit tests
  • 37. Component / Business process - notes ● Tracking - each component may track it’s own domain specific history changes ○ Consider tracking more than needed - business will ask soon about KPIs ○ To solve storage/performance issue implementation may use NoSQL ○ Tracking may be explicit (in domain) or implicit (via tracking dispatched events) ● Passing data to service methods ○ Simple types makes testing easier
  • 38. Shared kernel - notes ● Components commonly used by other Components (Event Dispatcher, Base Entity Classes, Traits, Scheduler) ● Changes may affect other Components
  • 39. Components relation to other components ● Assigning Entity reference to Entity from other component ○ In most cases ID is enough (avoid foreign keys) ○ Referencing different kinds of Entities by storing Context Type and Context ID, example: ■ Type Match and Match ID ■ Type Tournament and Tournament ID
  • 40. Relation on code level vs service level ● Code level ○ Single app instance ○ Higher level components may extend lower level components with plugins ○ Coupled code vs Dispatching Events ● Service level (SOA / Microservices) ○ No code sharing ○ Access only via API / Messaging
  • 41. Technical components ● Do not mix low level technical components with Domain ● Naming basing on Context: ○ Image processing ○ Communication (Websockets / HTTP / Queue) ○ Domain Framework (ie Interfaces for Commands, Dispatcher) ○ Addition to 3rd party framework (Symfony / Laravel)
  • 42. CQRS
  • 43. Command Query Responsibility Segregation Source: https://microservices.io/patterns/data/cqrs.html
  • 44. What if I don’t have full CQRS? ● Commands will use Services from domain ● Queries ○ In simplest form may use existing Repositories from Components ○ Consider separate Repository Interface for Commands/Services and Queries ○ Keep adding counters / redundant data step by step avoid complex joins and speed up queries ○ Over time Query Repository may use more advanced solutions
  • 50. My Class ● Is it technical, domain or connecting domain with framework? ● Is it for state change or reading? ● Is it generic or application/use case specific? ● Does it have state? ● Which properties are optimization purposes? ● What Bounded Contexts it should be aware of?
  • 51. Summary ● Chosen approach depends on team’s experience, available time, project’s lifespan ● Seek for Bounded Context in non DDD components/layers too! ● Coupling within Component is good. Unnecessary coupling between Components is bad. ● There are no strict rules, each team goes their own path ● Introduce new ideas in your project step by step ● Explore, make mistakes, improve
  • 52. Resources ● https://www.infoq.com/minibooks/domain-driven-design-quickly ● https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/ ● https://fideloper.com/hexagonal-architecture ● http://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html ● https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-i t-all-together/
  • 53. Questions? ● hawraniak@red-sky.pl ● Looking for challenges? rekrutacja@red-sky.pl