python: inheriting or composition

后端 未结 4 1204
夕颜
夕颜 2021-02-05 13:40

Let\'s say that I have class, that uses some functionality of dict. I used to composite a dict object inside and provide some access from

4条回答
  •  遥遥无期
    2021-02-05 14:03

    Should isinstance(my_object, dict) return True or False? In other words, if you accidentally give one of the objects to something that wants a dict, should it blithely try to use it as a dict? Probably not, so use composition.

提交回复
热议问题