[Gambas-user] Request for advice

John Dovey 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
John



On Tue, 13 Jul 2021 at 14:52, T Lee Davidson <t.lee.davidson at gmail.com>
wrote:

> 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:
> [code]
> Public Sub _new(cChat as JSONCollection)
> $id = cChat["id"]
> $type = cChat["type"]
> [snip]
> $photo = New tb_type_chatphoto(cChat["photo"])
> [snip]
> End Sub
> [/code]
>
> The _new() method of tb_type_chatphoto could be:
> [code]
> 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
> [/code]
>
>
> 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
> jsonChat["photo"]["big_file_id"].
>
> 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.
>
>
> --
> Lee
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210713/30272532/attachment-0001.htm>


More information about the User mailing list