Get instance of containing class

前端 未结 2 552
我寻月下人不归
我寻月下人不归 2020-12-19 17:28

Is it possible to access an object from a member object without passing and storing a reference? In the example below, could a given chair object get access to the house obj

相关标签:
2条回答
  • 2020-12-19 17:50

    There is no way to do that without the Chair having a reference to the House. From the point of view of the Chair, there is no relationship between it and a House. In fact, the Chair could belong to many Houses, or no Houses.

    0 讨论(0)
  • 2020-12-19 18:10

    First off, is this an example of a real problem or just an example for learning purposes?

    It's definitely not Chair's responsibility to check the house location. If you want to find all chairs in Miami you have to traverse the whole tree or give it a reference.

    0 讨论(0)
提交回复
热议问题