Save 37% off PRO during our Black Friday Sale! »

Mind Your Business ...and Its Logic

Mind Your Business ...and Its Logic

In spite of the myriad of technological advances we had over the past decades, the software industry is in a trouble: a huge percentage of projects fail to be delivered on-time, on-budget, and with the required quality. Are we missing something? Hell yes!

We build software to make our clients’ businesses more efficient. We do it by implementing the Business Logic, and it’s the cornerstone of all systems. Any malfunction in Business Logic undermines the very reason the system was built for. Yet despite its importance, this aspect of software engineering never got the spotlight it deserves. Time to fix this.

In this session you’ll get a toolbox for correctly implementing your system’s business logic:
* Overview of the major business domain modeling patterns
* A simple, yet strong heuristic for choosing a pattern that fits best your business domain
* Architectural ramifications of each pattern

B90ab53ba7cf16ed1a4bb679cc6751d7?s=128

Vladik Khononov

September 28, 2016
Tweet

Transcript

  1. AND ITS LOGIC MIND YOUR BUSINESS

  2. Vladik Khononov Chief Architect @ Internovus @vladikk http://vladikk.com

  3. BUSINESS LOGIC

  4. PRESENTATION LAYER BUSINESS LOGIC LAYER DATA ACCESS LAYER

  5. None
  6. PRESENTATION LAYER BUSINESS LOGIC LAYER DATA ACCESS LAYER

  7. Transaction Script Active Record Domain Model Event Sourced Domain Model

  8. TRANSACTION SCRIPT

  9. TRANSACTION SCRIPT ▸ Simple Business Logic ▸ CRUD ▸ Input

    Validation ▸ Extract Transform Load (ETL) ▸ Simple Data Structures ▸ Always leave the database in a consistent state
  10. 
 APPLICATION CREATE USER UPDATE USER SEARCH USERS DATABASE UI

  11. public class CreateUser { public void Execute(name, email) { try

    { DB.StartTransaction();
 var row = DB.NewUserRow();
 row.Name = name;
 row.Email = email;
 DB.Append(row);
 DB.Commit(); } catch { DB.Rollback();
 throw; } } }
  12. ACTIVE RECORD

  13. ACTIVE RECORD ▸ Simple Business Logic ▸ CRUD ▸ Input

    Validation ▸ Extract Transform Load (ETL) ▸ Complex Data Structures ▸ References / Collections ▸ Multiple Tables
  14. USER INTERESTS ID NAME Has
 many ADDRESS COUNTRY CITY STREET

  15. 
 APPLICATION CREATE USER UPDATE USER SEARCH USERS DATABASE UI

  16. 
 APPLICATION CREATE USER UPDATE USER SEARCH USERS UI 


    ACTIVE
 RECORDS USER DATABASE
  17. public class CreateUser { public void Execute(userDetails) { try {

    DB.StartTransaction();
 
 var user = new User();
 user.Name = userDetails.Name;
 user.Email = userDetails.Email;
 user.Save();
 
 DB.Commit(); } catch { DB.Rollback();
 throw; } } }
  18. public class User { public Guid Id { get; set;

    }
 public string Name { get; set; }
 public List<Interest> Interests { get; set; }
 public Address Address { get; set; } public void Save() { … }
 public void Delete() { … }
 public static User Get(Guid id) { … }
 public static List<User> GetAll() { … } }
  19. DOMAIN MODEL

  20. DOMAIN MODEL ▸ Complex Business Logic ▸ Business rules ▸

    Invariants ▸ Calculations ▸ Complex algorithms
  21. 
 APPLICATION CREATE USER UPDATE USER SEARCH USERS UI 


    ACTIVE
 RECORDS USER DATABASE
  22. 
 APPLICATION CREATE USER UPDATE USER SEARCH USERS UI 


    DOMAIN
 MODEL USER DATABASE
  23. 
 APPLICATION CREATE USER UPDATE USER SEARCH USERS UI 


    DOMAIN
 MODEL USER INFRASTRUCTURE
  24. DOMAIN MODEL ▸ Complex business logic ▸ Model business domain

    ▸ Objects: data + behavior ▸ Plain objects ▸ Minimal application level use cases
  25. public class UpdateUser { public void Execute(userDetails) { try {

    var user = usersRepository.Get(userDetails.Id);
 user.UpdateDetails(userDetails);
 usersRepository.Save(user); } catch { DB.Rollback();
 throw; } } }
  26. public class User { public Guid Id { get; private

    set; }
 public string Name { get; private set; }
 public List<Interest> Interests { get; private set; }
 public Address Address { get; private set; } public void UpdateDetails() { … }
 public void AddInterest() { … }
 public static User InitializeNew() { … } } public interface IUsersRepository { User Get(Guid id);
 void Save(User user);
 void Delete(User user); }
  27. 
 APPLICATION CREATE USER UPDATE USER SEARCH USERS UI 


    DOMAIN
 MODEL USER INFRASTRUCTURE
  28. EVENT SOURCED
 DOMAIN MODEL

  29. EVENT SOURCED DOMAIN MODEL ▸ Complex Business Logic ▸ Business

    rules ▸ Invariants ▸ Complex algorithms ▸ Deals w/ money ▸ Data analysis required ▸ Audit required by law
  30. EVENT SOURCED DOMAIN MODEL Phone Email Name Id 46464543 one@gmail.com

    James 1 34234343 two@gmail.com John 2
  31. public class NewUserInitialized { public Guid UserId { get; private

    set; }
 public string Name { get; private set; }
 public string Email { get; private set; } } public class NameChanged { public Guid UserId { get; private set; }
 public string NewName { get; private set; } } public class EmailChanged { public Guid UserId { get; private set; }
 public string NewEmail { get; private set; } }
  32. EVENT SOURCED DOMAIN MODEL ▸ UserInitialized(1, John, john@gmail.com) ▸ NameChanged(1,

    James) ▸ EmailChanged(1, james@gmail.com)
  33. 
 APPLICATION CREATE USER UPDATE USER SEARCH USERS UI 


    DOMAIN
 MODEL USER EVENT STORE
  34. Transaction Script Active Record Domain Model Event Sourced Domain Model

  35. APPLICATION ARCHITECTURE

  36. LAYERED ARCHITECTURE PRESENTATION LAYER BUSINESS LOGIC LAYER DATA ACCESS LAYER

  37. HEXAGONAL / PORTS & ADAPTERS / ONION / CLEAN ARCHITECTURE

    CORE SERVICES INFRASTRUCTURE
  38. CQRS - COMMAND QUERY RESPONSIBILITY SEGREGATION WRITE MODEL COMMANDS UI

    READ MODEL QUERIES
  39. «SHLIKHTA» ARCHITECTURE EVERYTHING

  40. EVENT SOURCED DOMAIN MODEL • Shlikhta Architecture • Layered Architecture

    • Hexagonal Architecture • CQRS • Transaction Script • Active Record • Domain Model • Event Sourced Domain Model
  41. TESTING STRATEGIES

  42. TESTS PYRAMID UI
 /
 End to End Service / API


    layer tests Unit Tests
  43. TESTS PYRAMID UI
 /
 End to End Service / API


    layer tests Unit Tests
  44. TESTS PYRAMID UI
 /
 End to End Service / API


    layer tests Unit Tests
  45. TESTS PYRAMID UI
 /
 End to End Service / API


    layer tests Unit Tests
  46. TESTING STRATEGIES • End to end tests • API layer

    tests • Unit tests • Unit tests • Transaction Script • Active Record • Domain Model • Event Sourced Domain Model
  47. LANGUAGE AND TECHNOLOGY

  48. PROGRAMMING STYLE • Procedural • Procedural / OOP • OOP

    • Functional • Transaction Script • Active Record • Domain Model • Event Sourced Domain Model
  49. DYNAMIC / STATIC TYPING • Dynamic • Dynamic • Static

    • Static • Transaction Script • Active Record • Domain Model • Event Sourced Domain Model
  50. RAMIFICATIONS ▸ Architectural style / pattern ▸ Testing strategy ▸

    Language and technology ▸ Programming style ▸ Language type
  51. DECISION HEURISTIC ▸ Is the business logic mostly CRUD /

    ETL? Yes ▸ Are the data structures simple? yes - Transaction Script ▸ Are the data structures simple? No -Active Record ▸ Is the business logic mostly CRUD / ETL? No ▸ Is advanced analysis required, or dealing w/ money? No
 Domain Model ▸ Is advanced analysis required, or dealing w/ money? Yes
 Event Sourced Domain Model
  52. TRANSACTION SCRIPT ACTIVE RECORD DOMAIN MODEL EVENT SOURCED DOMAIN MODEL

  53. AGILE ARCHITECTURE

  54. TRANSACTION SCRIPT / SHLIKHTA ACTIVE RECORD / LAYERS DOMAIN MODEL

    / HEXAGONAL EVENT SOURCED DOMAIN MODEL / CQRS
  55. DECISION SCOPE

  56. CAMPAIGN MANAGEMENT LEAD MANAGEMENT

  57. 
 CAMPAIGN MANAGEMENT 
 LEAD MANAGEMENT CREATIVE CATALOG CAMPAIGN PUBLISHING

    BILLING USERS MANAGEMENT SALES COMMISSIONS CALCULATION DESK MANAGEMENT VOIP MANAGEMENT
  58. SUMMARY

  59. Business Driven Architecture

  60. None
  61. QUESTIONS?

  62. THANK YOU Vladik Khononov Chief Architect @ Internovus @vladikk http://vladikk.com