Sending message to child from parent

后端 未结 3 1635
一生所求
一生所求 2021-01-21 06:02

I have class Child inherited from class Parent. What I want is to send message to child, which has implementation of that message. So it\'s like calling pure virtual function fr

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-21 06:37

    Inheritence does not remove the need for delegation. Those are mutually exclusive aspects of OOP. It sounds to me as though your are indeed trying to implement a delegator. The classes that it delegates to shouldn't be subclasses of it, but discrete classes. What you need here is composition, not inheritence.

提交回复
热议问题