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

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

Vladik Khononov

September 28, 2016
Tweet

More Decks by Vladik Khononov

Other Decks in Programming

Transcript

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

    Validation ▸ Extract Transform Load (ETL) ▸ Simple Data Structures ▸ Always leave the database in a consistent state
  2. 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; } } }
  3. ACTIVE RECORD ▸ Simple Business Logic ▸ CRUD ▸ Input

    Validation ▸ Extract Transform Load (ETL) ▸ Complex Data Structures ▸ References / Collections ▸ Multiple Tables
  4. 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; } } }
  5. 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() { … } }
  6. DOMAIN MODEL ▸ Complex Business Logic ▸ Business rules ▸

    Invariants ▸ Calculations ▸ Complex algorithms
  7. DOMAIN MODEL ▸ Complex business logic ▸ Model business domain

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

    var user = usersRepository.Get(userDetails.Id);
 user.UpdateDetails(userDetails);
 usersRepository.Save(user); } catch { DB.Rollback();
 throw; } } }
  9. 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); }
  10. EVENT SOURCED DOMAIN MODEL ▸ Complex Business Logic ▸ Business

    rules ▸ Invariants ▸ Complex algorithms ▸ Deals w/ money ▸ Data analysis required ▸ Audit required by law
  11. 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; } }
  12. EVENT SOURCED DOMAIN MODEL • Shlikhta Architecture • Layered Architecture

    • Hexagonal Architecture • CQRS • Transaction Script • Active Record • Domain Model • Event Sourced Domain Model
  13. TESTING STRATEGIES • End to end tests • API layer

    tests • Unit tests • Unit tests • Transaction Script • Active Record • Domain Model • Event Sourced Domain Model
  14. PROGRAMMING STYLE • Procedural • Procedural / OOP • OOP

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

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

    Language and technology ▸ Programming style ▸ Language type
  17. 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
  18. TRANSACTION SCRIPT / SHLIKHTA ACTIVE RECORD / LAYERS DOMAIN MODEL

    / HEXAGONAL EVENT SOURCED DOMAIN MODEL / CQRS
  19. 
 CAMPAIGN MANAGEMENT 
 LEAD MANAGEMENT CREATIVE CATALOG CAMPAIGN PUBLISHING

    BILLING USERS MANAGEMENT SALES COMMISSIONS CALCULATION DESK MANAGEMENT VOIP MANAGEMENT