[Gambas-user] Request for advice
dovey.john at gmail.com
Tue Jul 13 22:58:57 CEST 2021
Thank you. That's pretty clear now.
In terms of picking my poison, I'm leaning heavily in the direction of
using the JSON directly!!!
I'll experiment a little more and see how that goes.
All the best
On Tue, 13 Jul 2021 at 14:52, T Lee Davidson <t.lee.davidson at gmail.com>
> On 7/13/21 11:43 AM, John Dovey wrote:
> > Now I'm looking at one of the objects. (user) and setting the Property
> > for "photo" which is another object called chatphoto.
> > How do I implement this?
> > I've got
> > ---
> > tb_type_chat.class
> > Export
> > Property id As Long Use $id
> > Property type As String Use $type
> > ' etc then
> > Property photo As Tb_type_chatphoto Use $tb_type_chatphoto '<- This
> > obviously refers to a different object. in the Read function, I guess
> > I populate the new object?
> It would be preferable to populate the object in its _new() method as
> opposed to its Read() method.
> Let's assume that, using the tb_interface module, you have retrieved a
> Chat (JSON) object from the API server (with the getChat
> method?), decoded it to a JSONCollection, and returned it to the Main
> module in a JSONCollection called "jsonChat".
> You could populate your Chat object with just:
> Dim oChat = New tb_type_chat(jsonChat)
> The _new() method of tb_type_chat could be, in part:
> Public Sub _new(cChat as JSONCollection)
> $id = cChat["id"]
> $type = cChat["type"]
> $photo = New tb_type_chatphoto(cChat["photo"])
> End Sub
> The _new() method of tb_type_chatphoto could be:
> Public Sub _new(cPhoto as JSONCollection)
> $small_file_id = cPhoto["small_file_id"]
> $small_file_unique_id = cPhoto["small_file_unique_id"]
> $big_file_id = cPhoto["big_file_id"]
> $big_file_unique_id = cPhoto["big_file_unique_id"]
> End Sub
> This highlights one thing to me. Since JSON.Decode converts the JSON
> object into its appropriate Gambas type (most often
> collections), it actually might be much simpler to let the JSON component
> (and JSONCollection) handle the data structure instead
> of going through the pain (and possible confusion) of
> converting/transferring the data to objects. In that case, accessing the
> big_file_id of a Chat object's ChatPhoto object would simply be
> And, personally if it were me, I actually might do that since I prefer
> simplicity over strict OO adherence. But as I said,
> others prefer objects. Pick your poison.
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the User