Skip to content

Instantly share code, notes, and snippets.

class Address < ActiveRecord::Base
# here's where we'll use Addressable
belongs_to :addressable, :polymorphic => true
end
class Tagging < ActiveRecord::Base
public interface Addressable {
Address getAddress ();
void setAddress (Address address);
}
public class Address {
public interface Taggable {
Collection getTaggings ();
}
public class Tagging {
private Taggable taggable; // anyone who implements Taggable
class Person < ActiveRecord::Base
has_one :address, :as => :addressable
end
class Company < ActiveRecord::Base
has_one :address, :as => :addressable
class Address < ActiveRecord::Base
belongs_to :person
belongs_to :company
end
public interface Collection {
Collection <<(Object anObject);
}
public class Array implements Collection {
public Collection << (Object object) {
// add object to me
}
}
public class String implements Collection {
class Address < ActiveRecord::Base
end
class Person < Address
end
class Company < Address
end
class Addressable < ActiveRecord::Base
end
class Person < Addressable
end
class Company < Addressable
end
class Addressable < ActiveRecord::Base
has_one :address
end