Avoiding 'instanceof' in Java

后端 未结 8 458
灰色年华
灰色年华 2020-12-07 11:14

I have the following (maybe common) problem and it absolutely puzzles me at the moment:

There are a couple of generated event objects which extends the abstract clas

8条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 11:45

    Each event has a function, say do. Each subclass overrides do, to do (:P) the appropriate action. Dynamic dispatch does everything else afterwards. All you need to do, is call event.do()

提交回复
热议问题