Composer #182
TobiasHT5
started this conversation in
Team Posts
Composer
#182
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The Composer class is going to be located in the
parser.py
file as well. It's main function is to build out the dictionary from the object tree of telegram objects. The Composer class shall have one public method calledcompose
which shall take in the root object and walk the object tree, merging each converting each node to a base python type that can easily be converted into JSON.The compose method it's should not contain the details of composing every telegram object, or else the compose method would be too bulky and it's generally poor design. Instead, the objects themselves should have the ability to encode themselves in a composable way. It would be hectic to implement such a feature in each and every telegram object, but since this is a common feature that should cut across all telegram objects, it shall be implemented in the
BaseObject
of the telegram objects since it's inherited by all telegram objects.The base object shall have a
_compose
method who's job is to convert the object's attribute into types that can be encoded to JSON. The compose method of the Composer class while walking the object tree, will call the_compose
method of the telegram objects to encode themselves and merges the encode result into the dictionary that it's building. Once the dictionary is complete will elements that are encodeable in JSON, it converts the dictionary into a JSON string or else just returns the built disctionaryBeta Was this translation helpful? Give feedback.
All reactions