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

Where do I put my Business Logic? - Greach 2014...

Where do I put my Business Logic? - Greach 2014, Madrid, Spain

WHERE DO I HAVE TO PUT MY BUSINESS LOGIC?
GRAILS IS NOT MY DOMAIN MODEL.

Greach 2014, Madrid, Spain
Presented March, 28th, 2014

What’s business logic exactly? What’s a domain model? How does the use of a framework like Grails
influence how we build a domain model? How can the use of patterns helps us in building our system?
This talk will approach the problems that we have to face when we put a tool in the core of our
system and we will discuss whether the price we pay for using the Grails framework is too high.

A lot of resources at the end!!

More Decks by Antonio de la Torre Fernández

Other Decks in Programming

Transcript

  1. Where do I put my Business Logic? Antonio de la

    Torre @adelatorrefoss March 28th 2014 Grails is not my Domain Model
  2. Actions Single Responsibility Principle (SRP) SOLID Tell, don’t ask “Object

    Calisthenics. 9 steps to better SW design” , Jeff Bay GRASP
  3. Functional Programming - Inmutability - Transaction scripts - Stateless services

    - Stateless API - Rare workflows … - Objects with state… but we don’t usually use them “Why OO in web, when usually is DB -> Object -> Process -> Object -> DB” Functional Programming for the Object-Oriented Programmer Brian Marick
  4. “The goal of domain- driven design is to create better

    software by focusing on a model of the domain rather than the technology”
  5. Tackling complexity DDD is a way of dealing with complexity.

    Complex is easy. Simple is a lot harder.
  6. Ubiquitous Language “A language structured around the domain model and

    used by all team members to connect all the activities of the team with the software”
  7. Entities “When an object is distinguished by its identity, rather

    than its attributes, make this primary to its definition in the model”
  8. Value Objects “When you care only about the attributes of

    an element of the model, classify it as a VALUE OBJECT. Don’t give it any identity…”
  9. Services “When a significant process or transformation in the domain

    is not a natural responsibility of an ENTITY or VALUE OBJECT, add an operation to the model as a standalone interface declared as a SERVICE. Make the SERVICE stateless.”
  10. Modules “Choose MODULES that tell the story of the system

    and contain a cohesive set of concepts.”
  11. Aggregates “Cluster the ENTITIES and VALUE OBJECTS into AGGREGATES and

    define boundaries around each. Choose one ENTITY to be the root of each AGGREGATE, and control all access to the objects inside the boundary through the root. Allow external objects to hold references to the root only.”
  12. Factories “Shift the responsibility for creating instances of complex objects

    and AGGREGATES to a separate object, which may itself have no responsibility in the domain model but is still part of the domain design.”
  13. Repositories “For each type of object that needs global access,

    create an object that can provide the illusion of an in-memory collection of all objects of that type.”
  14. Implementing Entities These are Domain Classes in Grails. They come

    with persistence already resolved through GORM. hasOne vs. belongsTo property can be used to define the lifecycle of entities and their relationships.
  15. Implementing Value Objects In Grails, you can use “embedded” property

    in GORM field to manage a value object. And deal with them with POGO or Command Objects
  16. Implementing Aggregates Aggregates are implemented in the hasMany - belongsTo

    relationship. Can control the root access within a Service.
  17. Implementing Factories Implement Factories classes to create new instances with

    an abstract interface… It could be configurable with properties.
  18. Implementing Repositories Grails Service can be used to implement a

    dedicated Repository object that simply delegates its operation to Grails GORM.
  19. All together … In a more complex Aggregation, create a

    service to manage, this service acts as a Repository. Control invariants. To access a simple Entity use GORM. In a Domain Model with hasOne and belongsTo can act as an Aggregate Root, and use GORM directly. And we reserve Factories to instantiate external providers, like email service, S3 access, push mobile notifications, and so on …
  20. Resources Domain Driven Design Eric Evans http://www.slideshare.net/thinkddd/domain-driven-design-dddsydney-2011 - (Intro) Complex

    vs Simple http://pragprog.com/articles/tell-dont-ask - Tell, don't ask http://juan-garcia-carmona.blogspot.com.es/2012/11/solid-y-grasp-buenas-practicas-hacia-el.html - SOLID - Spanish http://www.martinfowler.com/bliki/AnemicDomainModel.html - Anemic Model
  21. Resources http://www.slideshare.net/sergiopolo/introduccin-a-ddd (Spanish) - Building Blocks http://www.slideshare.net/harshjegadeesan/domain-driven-design-presentation STARRED - Intro

    - Building Blocks http://www.slideshare.net/GlenWilson/domain-driven-design-pattern-summaries-presentation - Extense document with Pattern Summaries http://www.slideshare.net/ziobrando/taming-complex-domains-with-domain-driven-design-presentation STARRED!! - Building Blocks - Large Scale DDD
  22. Resources http://www.slideshare.net/DimkaG/domain-driven-design-and-model-driven-development - ideas to implement the building blocks. http://blog.refactoringin.net/2011/08/17/grails-as-a-ddd-platform/

    - Unique reference directly with Grails - Repository??? with GORM… Brian Marick - Functional Programming for the Object-Oriented Programmer https://leanpub.com/fp-oo http://www.mabishu.com/blog/2012/12/14/object-calisthenics-write-better-object-oriented-code/ Object Calisthenics Write Better OO Code Javier Acero - Mi dominio es mio y no lo comparto http://vimeo.com/69157481 (Spanish)