Active domain

  • 941 views
Uploaded on

Ruby Entity Manager, experimental ORM based on SOLID principles and Domain Driven Design

Ruby Entity Manager, experimental ORM based on SOLID principles and Domain Driven Design

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
941
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Transcript

  • 1. ActiveDomain An Experimental SOLID ORMThursday, December 2, 2010
  • 2. Me! • Franck Verrot • http://twitter.com/cesariogw • http://github.com/cesario • Currently awesoming at LeadformanceThursday, December 2, 2010
  • 3. This is all about • Software architecture • Principles I believe in • Current implementations and their limits • ActiveDomain!Thursday, December 2, 2010
  • 4. Software ArchitectureThursday, December 2, 2010
  • 5. SOLID principles • Single Responsibility • Open/Close • Liskov Substitution • Interface Segregation • Dependency InversionThursday, December 2, 2010
  • 6. Inspired by DDD • The cover sucks • DDD > Your Mom • Entities,Value Objects • Context Boundaries, ...Thursday, December 2, 2010
  • 7. Current implementationsThursday, 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 endThursday, December 2, 2010
  • 9. Pros Cons • Convention • Fine-tuning • High Level of Abstraction • Magic can be misleading • Easy to learn • Hard to specializeThursday, 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 endThursday, 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
  • 13. ActiveDomainThursday, 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 MappingThursday, 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 endThursday, 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 endThursday, 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 endThursday, 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 # => trueThursday, 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&AThursday, December 2, 2010