Skip to content

Instantly share code, notes, and snippets.

@eprothro
Last active September 14, 2017 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eprothro/11ac9ba54d5e68e5a7b5b3d59dc73e82 to your computer and use it in GitHub Desktop.
Save eprothro/11ac9ba54d5e68e5a7b5b3d59dc73e82 to your computer and use it in GitHub Desktop.

Builder Pattern

Pros

  • Familar
  • Clean abstraction from model
  • No model changes required

Cons

  • Slow, 2N loading with cassandra-driver

Data Object Pattern

class Person
  attr_accessor :name

  def initialize(opts={})
    @name = opts[:name]
  end
end
Person.new(name: "eprothro")

or when loading from a hash

p = Person.new
p.name = row["name"]

becomes

class Person
  include DataState

  data_attr :name

end
Person.new(name: "eprothro")

or when loading from a hash

p = Person.new(TableAdapater.new(row))

Pros

  • Fast, almost zero overhead added to cassandra-driver
  • Easy serialization
  • No public interface change
  • Easy to raise if state unknown (from selection without attr)

Cons

  • Not idiomatic
  • More code, code relations twice (data model, model model)
  • Complexity around contained non-primitives
  • Requires change to modeling
  • Theoretical muddiness with persisted-attributes concept in model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment