Domain Driven Design in the Browser - Cameron Edwards

59
Hi

description

hakkalabs.co

Transcript of Domain Driven Design in the Browser - Cameron Edwards

  • 1. Domain Driven Design in theBrowserBetter Living through Software Modeling

2. The job of software is to solveproblems having to do with aparticular domain. 3. Whats a Domain?A domain is an area of expertise.It could be a industry field, like accounting, or a subject ofinterest, like penguins. 4. MatchmakingOkCupid 5. Social NetworkingFacebook 6. Data AnalysisSumAll 7. Graphic DesignPhotoshop 8. ResearchEasyBib 9. Successful software startswith a focus on the domain. 10. How do I focus on thedomain? 11. First, seek understandingfrom domain experts.They know more than you do.experts are sometimes known as business stakeholders or product 12. Who is an expert in my domain? 13. MatchmakingThese people (shadchanim) 14. Social NetworkingThis guy. 15. Data AnalysisGeorge Box (a famous statistician) 16. Graphic DesignDavid Carson 17. ResearchAllison I Know a Lot About Research Cloyd 18. Next, create a model of the domainthat you can use in your software. 19. What is a model? 20. A blueprint of the domain thatexists in the mind of the developer. 21. 0100101111010101001001010101010100101001010101010010101010100010010010101010101010001001001000001110101010101000101011101101010110101001001000110100000011101010101010000010101010011010010101110100101011010101010101010101010101010001110001111001001100101010101000101010101110110101010010101001010101000000study researchhypothesis controlgroup experimentconjecture theoremlaw theory evidenceabstract introductionpremise discussionfindings conclusionfootnotes citationsreference explanationmethodology thesissupport databaseexplication essaynews opinion booksource review peereditor commentaryempirical history case 22. Some common misconceptionsabout the model 23. The model is notsource code.You have code that reflects the model,and it contains words that come from themodel.But code is just an implementation ofthe model. The model exists in the mindof the developer. 24. The model is notthe database.Some of the data associated with themodel is in the database. And thedatabase schema is anotherimplementation of the model.But the model encompasses all of thedomain logic AND data, and it exists inthe mind of the developer. 25. The model is not adiagramA diagram is just a picture of the model.The model itself exists in the mind ofthe developer. 26. Some perks of using a model 27. Ubiquitous Language 28. Scalably Handling Complexity 29. Manageable Knowledge Sharing 30. How do I translate the domainexperts knowledge into a model? 31. 1.Verbal Communication2.Diagramming3.Use Cases 32. The Stuff that Models areMade Of 33. EntitiesObjects with a unique, persistent identityWe track this identity using a key or a combination ofproperties 34. Some examples of entities:Entity Type Identifier Person/User Email Bank Account Account # Shipping Route Id Book ISBN 35. Value ObjectsSecond class objects with no identity, just valueValue objects are always properties of entitiesTheyre immutable: theyre usually only changed byreplacement 36. Name 37. FactoriesThe job of factories is to make entities 38. Printer 39. ServicesServices are the verbs of an application.Their state doesnt matter so much.They have a job to do. 40. CitationService 41. CitationService.formatBook(string title, CiteStyle style)1. Call the WorldCat API to get publication info about the book.2. Pass the WorldCat response object to BookFactory.fromWorldCat()3. For analytics, pass the Book object to BookRepository and callBookRepository.save().4. Using the name of the CiteStyle, pass the Book to a ViewFactoryfor formatting and return the View. 42. RepositoriesThe persistence layerBuckets for data 43. Some Benefits of Repositories A repository is an interface, so you can read and write persistentdata without knowing where its going. You can say repository.read()and it might read from a REST API, web sockets, local storage, oreven memory. Thats why a repository is called a Persistence Abstraction Layer. 44. Layered Architecture 45. ApplicationDomainUtilities 46. Application Layer Views RequestControllers (traditionally called Controllers) ViewModels Assets - CSS, JavaScript, images UI Details - UIControllers, Data Bindings Any other application-specific logic (console applications, cron tasks,etc.) 47. Domain Layer Entities Factories Services Repositories Any other domain-specific logic thats reusable across applications 48. Utilities Layer Libraries - Math Utilities, CSV Parsers, DOM Selection Utilities, DataStructure Helpers, ORM Tools Frameworks - Backbone, Symfony, Rails, Django Anything thats reusable across domains 49. Some Rules for Layered Architecture 50. Information flows one way: up 51. ReferencesObjects in one layer can refer to objects in any lower layer.Objects in one layer can refer to objects in that same layer.Objects in one layer CANNOT REFER TO OBJECTS IN A HIGHER LAYER. 52. Lets Get Some PracticeFor some more good reading, go to http://www.loewenbraeuzelt.de/wp-content/uploads/DomainDrivenDesignQuicklyOnline.pdfOr check out Eric Evans Book, Domain Driven Design 53. In This Presentation See the working app: cornellnotes.nodejitsu.com GraphJS: https://github.com/cameronprattedwards/graphjs entity-context: https://github.com/cameronprattedwards/entity-contextContributors wanted!