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

Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Karsten Dambekalns
 
What makes a good bug report?
What makes a good bug report?What makes a good bug report?
What makes a good bug report?Rahul Premraj
 
Doctrator Symfony Live 2011 San Francisco
Doctrator Symfony Live 2011 San FranciscoDoctrator Symfony Live 2011 San Francisco
Doctrator Symfony Live 2011 San Franciscopablodip
 
Entity Query API
Entity Query APIEntity Query API
Entity Query APImarcingy
 

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

Intergrity Stock Exchange (2)
Intergrity   Stock Exchange (2)Intergrity   Stock Exchange (2)
Intergrity Stock Exchange (2)Niro11
 
Press Book Mathilde Durieux
Press Book Mathilde DurieuxPress Book Mathilde Durieux
Press Book Mathilde DurieuxMathilde Durieux
 
Online mrm ver1.0
Online mrm ver1.0Online mrm ver1.0
Online mrm ver1.0vijaydsouza
 
Learning and Development in Organizations
Learning and Development in OrganizationsLearning and Development in Organizations
Learning and Development in OrganizationsRobert A. Sedlák
 

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 ActiveDomain An Experimental SOLID ORM

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 PHPGuilherme Blanco
 
Doctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 ParisDoctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 Parispablodip
 
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 PHPGiorgio Sironi
 
A Tour Through the Groovy Ecosystem
A Tour Through the Groovy EcosystemA Tour Through the Groovy Ecosystem
A Tour Through the Groovy EcosystemLeonard Axelsson
 
Ruby on CouchDB - SimplyStored and RockingChair
Ruby on CouchDB - SimplyStored and RockingChairRuby on CouchDB - SimplyStored and RockingChair
Ruby on CouchDB - SimplyStored and RockingChairJonathan Weiss
 
How to make DSL
How to make DSLHow to make DSL
How to make DSLYukio Goto
 
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 Daniel Petisme
 
Active Support Core Extensions (1)
Active Support Core Extensions (1)Active Support Core Extensions (1)
Active Support Core Extensions (1)RORLAB
 
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 PHPGiorgio Sironi
 
Apache ant
Apache antApache ant
Apache antkoniik
 
Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v RubyJano Suchal
 
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...MongoDB
 
Cleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQueryCleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQueryRebecca Murphey
 
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 ExamplesMike Friedman
 
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 ExamplesLewis Lin 🦊
 
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 ...MongoDB
 
Choosing a Shard key
Choosing a Shard keyChoosing a Shard key
Choosing a Shard keyMongoDB
 

Similar to ActiveDomain An Experimental SOLID ORM (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

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 

Recently uploaded (20)

Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 

ActiveDomain An Experimental SOLID ORM

  • 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