如何将其他模型类整齐地包装在一个类中?

时间:2019-01-18 20:32:51

标签: python python-3.x oop

我做了一个包装,最近我反思了我认为是一个糟糕的设计决策,但是,我不确定哪种选择更好。

当前,我的包装器的工作方式如下(名称已更改):

    import wrapper
    api = wrapper.Api(params...)
    # fetch fetches data from the API
    objects = wrapper.model.fetch(api, params...)
    # get_special might be only relevant to a certain object type
    other_objects = wrapper.other_model.get_special(api, params...)

很显然,将API作为参数传递并不是很糟糕,无论它看起来是否糟糕。我考虑过将所有这些类都放在API类中,但是我也不认为这是个好主意。什么是更好的设计选择?

预先感谢:D

根据要求,我要添加更多详细信息。 我的应用程序是网站launchlibrary.net的包装,该网站提供了有关火箭发射的数据。在这里可用-https://github.com/Plutoberth/python-launch-library

基本上,我不确定如何以既简洁又不需要您每次都通过API的方式来实现这一点。我的理想方法是这样,但我认为这需要在API中添加这些函数,这会使它变得非常庞大。

import launchlibrary as ll # the wrapper
api = ll.Api(params..)
launches = api.Launch(params...)

我想这更多的是设计问题,而不是实现问题。实现那段代码是微不足道的,但这会使我的API类变得庞大。

0 个答案:

没有答案