[Prev][Next][Index][Thread]

Re: Dylan, MOP, object/relational mapping...






Scott Ribe <sribe@miqs.com> wrote:
>
>Yes you're misunderstanding EOGenericRecord. It does automagically
>provide the getFoo and setFoo methods based on the data dictionary. The
>point is that you do NOT have to write the accessor methods unless you
>want them to do something special besides the normal fetching and
>assignment. So you add an attribute to the data dictionary and *poof* it
>has accessor methods (provided that you specify it's visible and
>modifiable). 

Gotcha. I don't think there's any way to automagically generate foo
and foo-setter methods, but you can define the record as a collection.
Then if you define an element() methods for your type, you can add
singleton methods as you need them to approximate how your ObjC code
was functioning. An example:

  define class <record> (<collection>)
    slot my-dict :: <table>;
  end class <record>;
  
  define method element(c :: <record>, key :: <object>) => (o :: <object>)
    c.my-dict[key];
  end method element;

So if you have a record rec, say, you could do the following to get
fields out of it. (I'm assuming it's indexed by symbols, but it could
be anything.)

  let name = rec[#"name"];
  let salary = rec[#"salary"];
  ...

If you want to do something special with one of the fields (say check
for authorization), you can write a singleton method on the appropriate
key:

  define method element(c :: <record>, key == #"salary") => (o :: <object>)
    if (*am-i-the-boss?*)  
      c.my-dict[#"salary"];
    else
      signal(make(<not-the-boss-error>));
    end if;
  end method element;

So now there's no way to look at rec[#"salary"] unless the variable
*am-i-the-boss?* is not false. Plus there's something similar you can
do with element-setter. I do hope Andrew Shalit isn't cringing at
this. :)

>Now, watch while the damn software out there posts this response
>repeatedly just like it did my original message and your response to it.
>I just hope the replication is linear and not exponential ;-)

It looked like the Harlequin mail-to-news gateways is frotzed. I hope
there's someone still tending the list it over there. 


Neel