saasbook

obeying SRP by using composition

Oct 15th, 2012
923
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.45 KB | None | 0 0
  1. # table 'customers' has columns 'adr_street', 'adr_city', 'adr_zip'
  2. class Customer < ActiveRecord::Base
  3.   composed_of :customer_address,
  4.     :mapping => [['adr_street', 'street'], ['adr_city', 'city'], ['adr_zip','zip']]
  5. end
  6.  
  7. class CustomerAddress
  8.   attr_reader :street, :city, :zip
  9.   def initialize(street,city,zip) ;  @street,@city,@zip = street,city,zip ; end
  10.   def close_to?(other_address) ; ... ; end
  11.   def ==(other_address) ; ... ; end
  12. end
Advertisement
Add Comment
Please, Sign In to add comment