[Nitro] Concerns over Og mandating the form of initialize

George Moschovitis george.moschovitis at gmail.com
Wed Apr 13 15:16:48 EDT 2005


> applications to be able to create or alter data. I see this as a feature.

ok...

> When my Nitro app reads data and creates objects, I want to be sure the
> created objects are well-constructed.

you can add a og post-read callback to validate the object. (In the
next version this will be much easier and powerful, thanks to the
aspects).
 
> What would be the overhead of saving an object's properties as simple
> data, but also using an extra field to store a YAML serialization, and
> ...
> values in the database, or revive existing objects from the saved
> serialization?

this feels wrong. You are duplicating the data. Plus there is another
problem. If you attach a yaml representation to every DBMS row, you
cant have constant length records (which are much faster to traverse
by the DBMS system).

BTW, I think it is wrong to call the initialize method when an object
is deserialized. In the initialize method I may put code that should
be called when the object is initialized, ie created for the first
time. For example I could have code for reference counting in the
constructor:

def initialize 
  Statistics.num_of_blogs += 1
end

It would be bad to force this code executed every time the object was
deserialised.

If you want to ensure a valid state for your object you could do the
following (some 0.16.0 concepts here):

class MyObject

  # 0.16.0 aspect to intercept lifecycle callback
  post :make_valid, :on => og_read

  def initialize(...)
     ...
     make_valid
     ...
  end

  def make_valid
    # ensure a valid state for the object
  end

end

then make_valid is called after (post) each object is deserialized (read) from
the DBMS.

does this make sense to you?

George.



-- 
http://nitro.rubyforge.org
http://www.joy.gr




More information about the Nitro-general mailing list