SlideShare a Scribd company logo
1 of 20
ActiveDomain
                             An Experimental SOLID ORM




Thursday, December 2, 2010
Me!

                    • Franck Verrot
                    • http://twitter.com/cesariogw
                    • http://github.com/cesario

                    • Currently awesoming at Leadformance

Thursday, December 2, 2010
This is all about

                    • Software architecture
                    • Principles I believe in
                    • Current implementations and their limits
                    • ActiveDomain!

Thursday, December 2, 2010
Software Architecture



Thursday, December 2, 2010
SOLID
                               principles
                    • Single Responsibility
                    • Open/Close
                    • Liskov Substitution
                    • Interface Segregation
                    • Dependency Inversion

Thursday, December 2, 2010
Inspired by DDD

                    • The cover sucks
                    • DDD > Your Mom
                    • Entities,Value Objects
                    • Context Boundaries, ...

Thursday, December 2, 2010
Current
                             implementations


Thursday, December 2, 2010
You do that
                                                 ActiveRecord
     1 class Post                     1 class Post < ActiveRecord::Base
   2   include DataMapper::Resource   2   has_many :comments
   3                                  3 end
   4   property :id, Serial
   5
   6   has n, :comments
   7 end




Thursday, December 2, 2010
Pros                     Cons

        •      Convention                  •   Fine-tuning

        •      High Level of Abstraction   •   Magic can be misleading

        •      Easy to learn               •   Hard to specialize




Thursday, December 2, 2010
You might do that too
                                                   ActiveRecord
     1 class Post                       1 class Post < ActiveRecord::Base
   2    include DataMapper::Resource    2   vestal_version
   3    is :nested_set,                 3   acts_as_paranoid
             :scope => [ :user_id ]     4   set_table_name ‘articles’
   4    property :id,    Serial         5   set_primary_key ‘arti_id’
   5    property :title, String         6   has_many :comments,
   6    has n, :comments                7          :through => :articles,
   7 end                                8          :foreign_key => :id
                                        9   before_validate :do_stuff
                                       10   def do_stuff
                                       11     ...
                                       12   end
                                       13 end
Thursday, December 2, 2010
Architecture at risk
                                  (scary title I know)




Thursday, December 2, 2010
Issues

                    • Separation of concerns
                    • Testing the layers independently
                    • Efficiency ( Transactions, Memory footprint)
                    • Side effects (Lazy loading, non-“PORO”)


Thursday, December 2, 2010
ActiveDomain



Thursday, December 2, 2010
Features

                    • “Plain Old Ruby Object”
                    • Unit of Work
                    • DB agnostic from the start
                    • Could be used to build an AR-like ORM
                    • Identity Mapping

Thursday, December 2, 2010
In Action 1/4
                             describe "User" do
                               it "has many posts" do
                                 user = Entity::User.new :email => 'test@test.com'
                                 user.posts << Entity::Post.new(:title => 'Test post')
                                 user.should have(1).post
                               end
                             end

                             module Entity
                               class User
                                 include ActiveModel::Validations
                                 attr_reader :id
                                 attr_accessor :email, :name, :posts
                                 validates :email, :presence => true

                                 def who
                                   "i am #{name} (#{email})"
                                 end

                                 def initialize args = {}
                                   self.email = args.fetch(:email, nil)
                                   self.name = args.fetch(:name, nil)
                                   self.posts = args.fetch(:posts, [])
                                 end
                               end
                             end

Thursday, December 2, 2010
In Action 2/4

                             module Repository
                               class User < ActiveDomain::Repository::Base
                                 adapter :mysql
                                 table   :users
                                 dsn     'mysql://root:@localhost:3306/test'
                               end
                             end




Thursday, December 2, 2010
In Action 3/4
                             module Mapping
                               class User < ActiveDomain::Mapper::Base
                                 entity       Entity::User
                                 repository   Repository::User

                                 map {
                                   id    :id
                                   email :email
                                 }

                                 associations {
                                   has_many Entity::Post,
                                      :as => :posts,
                                      :conditions => { :id => :author_id }
                                 }
                               end
                             end




Thursday, December 2, 2010
In Action 4/4
                             $EM = ActiveDomain::EntityManager::Base.new do
                               register :users, Mapping::User
                             end

                             user = Entity::User.new :email => 'test@test.com'
                             $EM.users.attach(user) #object marked as new
                             $EM.flush #object persisted

                             user_found = $EM.users.find(:email => "test@test.com")
                             user == user_found # => true




Thursday, December 2, 2010
Is it ready yet?

                    • No!
                    • Associations don’t work yet
                    • Identity mapper in progress
                    • Will be released when it’ll work :)

Thursday, December 2, 2010
Thanks for listening!
                                    Q&A


Thursday, December 2, 2010

More Related Content

What's hot (6)

Build your own entity with Drupal
Build your own entity with DrupalBuild your own entity with Drupal
Build your own entity with Drupal
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3
 
What makes a good bug report?
What makes a good bug report?What makes a good bug report?
What makes a good bug report?
 
Doctrator Symfony Live 2011 San Francisco
Doctrator Symfony Live 2011 San FranciscoDoctrator Symfony Live 2011 San Francisco
Doctrator Symfony Live 2011 San Francisco
 
Entity Query API
Entity Query APIEntity Query API
Entity Query API
 

Viewers also liked (7)

Intergrity Stock Exchange (2)
Intergrity   Stock Exchange (2)Intergrity   Stock Exchange (2)
Intergrity Stock Exchange (2)
 
Press Book Mathilde Durieux
Press Book Mathilde DurieuxPress Book Mathilde Durieux
Press Book Mathilde Durieux
 
Live-Note
Live-NoteLive-Note
Live-Note
 
My Christmas Holidays
My Christmas HolidaysMy Christmas Holidays
My Christmas Holidays
 
Online mrm ver1.0
Online mrm ver1.0Online mrm ver1.0
Online mrm ver1.0
 
Rails is Secure
Rails is SecureRails is Secure
Rails is Secure
 
Learning and Development in Organizations
Learning and Development in OrganizationsLearning and Development in Organizations
Learning and Development in Organizations
 

Similar to Active domain

Doctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 ParisDoctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 Paris
pablodip
 
Pursuing practices of Domain-Driven Design in PHP
Pursuing practices of Domain-Driven Design in PHPPursuing practices of Domain-Driven Design in PHP
Pursuing practices of Domain-Driven Design in PHP
Giorgio Sironi
 
Apache ant
Apache antApache ant
Apache ant
koniik
 
Cleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQueryCleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQuery
Rebecca Murphey
 

Similar to Active domain (20)

IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPIPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
 
Doctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 ParisDoctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 Paris
 
Pursuing practices of Domain-Driven Design in PHP
Pursuing practices of Domain-Driven Design in PHPPursuing practices of Domain-Driven Design in PHP
Pursuing practices of Domain-Driven Design in PHP
 
Libertyvasion2010
Libertyvasion2010Libertyvasion2010
Libertyvasion2010
 
A Tour Through the Groovy Ecosystem
A Tour Through the Groovy EcosystemA Tour Through the Groovy Ecosystem
A Tour Through the Groovy Ecosystem
 
Ruby on CouchDB - SimplyStored and RockingChair
Ruby on CouchDB - SimplyStored and RockingChairRuby on CouchDB - SimplyStored and RockingChair
Ruby on CouchDB - SimplyStored and RockingChair
 
How to make DSL
How to make DSLHow to make DSL
How to make DSL
 
Diary of a Java dev lost in the .Net world - MugInClermont
Diary of a Java dev lost in the .Net world - MugInClermont Diary of a Java dev lost in the .Net world - MugInClermont
Diary of a Java dev lost in the .Net world - MugInClermont
 
Active Support Core Extensions (1)
Active Support Core Extensions (1)Active Support Core Extensions (1)
Active Support Core Extensions (1)
 
Pursuing Domain-Driven Design practices in PHP
Pursuing Domain-Driven Design practices in PHPPursuing Domain-Driven Design practices in PHP
Pursuing Domain-Driven Design practices in PHP
 
Metaprogramming
MetaprogrammingMetaprogramming
Metaprogramming
 
Apache ant
Apache antApache ant
Apache ant
 
Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v Ruby
 
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
 
Cleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQueryCleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQuery
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World Examples
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World Examples
 
MongoDB London 2013: Data Modeling Examples from the Real World presented by ...
MongoDB London 2013: Data Modeling Examples from the Real World presented by ...MongoDB London 2013: Data Modeling Examples from the Real World presented by ...
MongoDB London 2013: Data Modeling Examples from the Real World presented by ...
 
Chapter2 bag2
Chapter2 bag2Chapter2 bag2
Chapter2 bag2
 
Choosing a Shard key
Choosing a Shard keyChoosing a Shard key
Choosing a Shard key
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Active domain

  • 1. ActiveDomain An Experimental SOLID ORM Thursday, December 2, 2010
  • 2. Me! • Franck Verrot • http://twitter.com/cesariogw • http://github.com/cesario • Currently awesoming at Leadformance Thursday, December 2, 2010
  • 3. This is all about • Software architecture • Principles I believe in • Current implementations and their limits • ActiveDomain! Thursday, December 2, 2010
  • 5. SOLID principles • Single Responsibility • Open/Close • Liskov Substitution • Interface Segregation • Dependency Inversion Thursday, December 2, 2010
  • 6. Inspired by DDD • The cover sucks • DDD > Your Mom • Entities,Value Objects • Context Boundaries, ... Thursday, December 2, 2010
  • 7. Current implementations Thursday, December 2, 2010
  • 8. You do that ActiveRecord 1 class Post 1 class Post < ActiveRecord::Base 2 include DataMapper::Resource 2 has_many :comments 3 3 end 4 property :id, Serial 5 6 has n, :comments 7 end Thursday, December 2, 2010
  • 9. Pros Cons • Convention • Fine-tuning • High Level of Abstraction • Magic can be misleading • Easy to learn • Hard to specialize Thursday, December 2, 2010
  • 10. You might do that too ActiveRecord 1 class Post 1 class Post < ActiveRecord::Base 2 include DataMapper::Resource 2 vestal_version 3 is :nested_set, 3 acts_as_paranoid :scope => [ :user_id ] 4 set_table_name ‘articles’ 4 property :id, Serial 5 set_primary_key ‘arti_id’ 5 property :title, String 6 has_many :comments, 6 has n, :comments 7 :through => :articles, 7 end 8 :foreign_key => :id 9 before_validate :do_stuff 10 def do_stuff 11 ... 12 end 13 end Thursday, December 2, 2010
  • 11. Architecture at risk (scary title I know) Thursday, December 2, 2010
  • 12. Issues • Separation of concerns • Testing the layers independently • Efficiency ( Transactions, Memory footprint) • Side effects (Lazy loading, non-“PORO”) Thursday, December 2, 2010
  • 14. Features • “Plain Old Ruby Object” • Unit of Work • DB agnostic from the start • Could be used to build an AR-like ORM • Identity Mapping Thursday, December 2, 2010
  • 15. In Action 1/4 describe "User" do   it "has many posts" do     user = Entity::User.new :email => 'test@test.com'     user.posts << Entity::Post.new(:title => 'Test post')     user.should have(1).post   end end module Entity   class User     include ActiveModel::Validations     attr_reader :id     attr_accessor :email, :name, :posts     validates :email, :presence => true     def who       "i am #{name} (#{email})"     end     def initialize args = {}       self.email = args.fetch(:email, nil)       self.name = args.fetch(:name, nil)       self.posts = args.fetch(:posts, [])     end   end end Thursday, December 2, 2010
  • 16. In Action 2/4 module Repository   class User < ActiveDomain::Repository::Base     adapter :mysql     table :users     dsn 'mysql://root:@localhost:3306/test'   end end Thursday, December 2, 2010
  • 17. In Action 3/4 module Mapping   class User < ActiveDomain::Mapper::Base     entity Entity::User     repository Repository::User     map {       id :id       email :email     }     associations {       has_many Entity::Post, :as => :posts, :conditions => { :id => :author_id }     }   end end Thursday, December 2, 2010
  • 18. In Action 4/4 $EM = ActiveDomain::EntityManager::Base.new do   register :users, Mapping::User end user = Entity::User.new :email => 'test@test.com' $EM.users.attach(user) #object marked as new $EM.flush #object persisted user_found = $EM.users.find(:email => "test@test.com") user == user_found # => true Thursday, December 2, 2010
  • 19. Is it ready yet? • No! • Associations don’t work yet • Identity mapper in progress • Will be released when it’ll work :) Thursday, December 2, 2010
  • 20. Thanks for listening! Q&A Thursday, December 2, 2010

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n