Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mind Your Business. And Its Logic

165 views

Published on

Slides for my presentation "Mind Your Business. And Its Logic"

Published in: Software
  • Be the first to comment

Mind Your Business. And Its Logic

  1. 1. AND ITS LOGIC MIND YOUR BUSINESS
  2. 2. Vladik Khononov Chief Architect @ Internovus @vladikk http://vladikk.com
  3. 3. BUSINESS LOGIC
  4. 4. PRESENTATION LAYER BUSINESS LOGIC LAYER DATA ACCESS LAYER
  5. 5. 💵
  6. 6. PRESENTATION LAYER BUSINESS LOGIC LAYER DATA ACCESS LAYER
  7. 7. Transaction Script Active Record Domain Model Event Sourced Domain Model
  8. 8. TRANSACTION SCRIPT
  9. 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. 10. 
 APPLICATIONCREATE USER UPDATE USER SEARCH USERS DATABASE UI
  11. 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. 12. ACTIVE RECORD
  13. 13. ACTIVE RECORD ▸ Simple Business Logic ▸ CRUD ▸ Input Validation ▸ Extract Transform Load (ETL) ▸ Complex Data Structures ▸ References / Collections ▸ Multiple Tables
  14. 14. USER INTERESTS ID NAME Has
 many ADDRESSCOUNTRY CITY STREET
  15. 15. 
 APPLICATIONCREATE USER UPDATE USER SEARCH USERS DATABASE UI
  16. 16. 
 APPLICATIONCREATE USER UPDATE USER SEARCH USERS UI 
 ACTIVE
 RECORDS USER DATABASE
  17. 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. 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. 19. DOMAIN MODEL
  20. 20. DOMAIN MODEL ▸ Complex Business Logic ▸ Business rules ▸ Invariants ▸ Calculations ▸ Complex algorithms
  21. 21. 
 APPLICATIONCREATE USER UPDATE USER SEARCH USERS UI 
 ACTIVE
 RECORDS USER DATABASE
  22. 22. 
 APPLICATIONCREATE USER UPDATE USER SEARCH USERS UI 
 DOMAIN
 MODEL USER DATABASE
  23. 23. 
 APPLICATIONCREATE USER UPDATE USER SEARCH USERS UI 
 DOMAIN
 MODEL USER INFRASTRUCTURE
  24. 24. DOMAIN MODEL ▸ Complex business logic ▸ Model business domain ▸ Objects: data + behavior ▸ Plain objects ▸ Minimal application level use cases
  25. 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. 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. 27. 
 APPLICATIONCREATE USER UPDATE USER SEARCH USERS UI 
 DOMAIN
 MODEL USER INFRASTRUCTURE
  28. 28. EVENT SOURCED
 DOMAIN MODEL
  29. 29. EVENT SOURCED DOMAIN MODEL ▸ Complex Business Logic ▸ Business rules ▸ Invariants ▸ Complex algorithms ▸ Deals w/ money ▸ Data analysis required ▸ Audit required by law
  30. 30. EVENT SOURCED DOMAIN MODEL PhoneEmailNameId 46464543one@gmail.comJames1 34234343two@gmail.comJohn2
  31. 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. 32. EVENT SOURCED DOMAIN MODEL ▸ UserInitialized(1, John, john@gmail.com) ▸ NameChanged(1, James) ▸ EmailChanged(1, james@gmail.com)
  33. 33. 
 APPLICATIONCREATE USER UPDATE USER SEARCH USERS UI 
 DOMAIN
 MODEL USER EVENT STORE
  34. 34. Transaction Script Active Record Domain Model Event Sourced Domain Model
  35. 35. APPLICATION ARCHITECTURE
  36. 36. LAYERED ARCHITECTURE PRESENTATION LAYER BUSINESS LOGIC LAYER DATA ACCESS LAYER
  37. 37. HEXAGONAL / PORTS & ADAPTERS / ONION / CLEAN ARCHITECTURE CORE SERVICES INFRASTRUCTURE
  38. 38. CQRS - COMMAND QUERY RESPONSIBILITY SEGREGATION WRITE MODEL COMMANDS UI READ MODEL QUERIES
  39. 39. «SHLIKHTA» ARCHITECTURE EVERYTHING
  40. 40. EVENT SOURCED DOMAIN MODEL • Shlikhta Architecture • Layered Architecture • Hexagonal Architecture • CQRS • Transaction Script • Active Record • Domain Model • Event Sourced Domain Model
  41. 41. TESTING STRATEGIES
  42. 42. TESTS PYRAMID UI
 /
 End to End Service / API
 layer tests Unit Tests
  43. 43. TESTS PYRAMID UI
 /
 End to End Service / API
 layer tests Unit Tests
  44. 44. TESTS PYRAMID UI
 /
 End to End Service / API
 layer tests Unit Tests
  45. 45. TESTS PYRAMID UI
 /
 End to End Service / API
 layer tests Unit Tests
  46. 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. 47. LANGUAGE AND TECHNOLOGY
  48. 48. PROGRAMMING STYLE • Procedural • Procedural / OOP • OOP • Functional • Transaction Script • Active Record • Domain Model • Event Sourced Domain Model
  49. 49. DYNAMIC / STATIC TYPING • Dynamic • Dynamic • Static • Static • Transaction Script • Active Record • Domain Model • Event Sourced Domain Model
  50. 50. RAMIFICATIONS ▸ Architectural style / pattern ▸ Testing strategy ▸ Language and technology ▸ Programming style ▸ Language type
  51. 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. 52. TRANSACTION SCRIPT ACTIVE RECORD DOMAIN MODEL EVENT SOURCED DOMAIN MODEL
  53. 53. AGILE ARCHITECTURE
  54. 54. TRANSACTION SCRIPT / SHLIKHTA ACTIVE RECORD / LAYERS DOMAIN MODEL / HEXAGONAL EVENT SOURCED DOMAIN MODEL / CQRS
  55. 55. DECISION SCOPE
  56. 56. CAMPAIGN MANAGEMENT LEAD MANAGEMENT
  57. 57. 
 CAMPAIGN MANAGEMENT 
 LEAD MANAGEMENT CREATIVE CATALOG CAMPAIGN PUBLISHING BILLING USERS MANAGEMENT SALES COMMISSIONS CALCULATION DESK MANAGEMENT VOIP MANAGEMENT
  58. 58. SUMMARY
  59. 59. Business Driven Architecture
  60. 60. QUESTIONS?
  61. 61. THANK YOU Vladik Khononov Chief Architect @ Internovus @vladikk http://vladikk.com

×