![]() ![]() ![]() Note that Python itself uses basically the same strategy when storing instance members:Ī class instance has a namespace implemented as a dictionary which is the first place in which attribute references are searched. For convenience, define the _getattr_(…) method. You should consider using a generator in your get_list_of_all_files: you should yield each File, instead of returning the completed list.Ī quick-and-dirty solution is to just store the whole dictionary as-is. Your constructor has the input public_key but does not store that as a property. Your class has a lot of related data, it has to get in there somehow. ![]() But, not everything can be small, and pretty. The answer is: yes, it is large, and the code is ugly. My colleague says that the constructor is very large, and this code is horrible. It is 'tailored' to match the JSON data format, and it works well. RecommendationĪs for me, given the nature of your JSON data, it appears that the large constructor is the lesser of the evils. Once you have sub-categorized your parameters, the constructor becomes simpler, like: def _init_(self, name, locations, times, types, md5, size, public_key=None, preview=None):īut, though you have simplified this class's constructor, you now have to build up a hierarchy of data to initialize it. Then the file locations could be grouped as well class FileLocation():ĭef _init_(self, path, public_url=None):įileGroup would be, perhaps, the various 'types', like type, media_type, mime_type. For example, the two times could be one class: class FileTimes(): The sub-cateogory option is not awful, it is done by grouping related parameters together. The post-constructor modifier system will have a bunch of 'set' methods, and you call them like: tSize(.) Your code is an example of the large constructor. There are three ways I know of to deal with large container classes: ![]()
0 Comments
Leave a Reply. |