Is it ever valid to convert an object from a base class to a subclass

后端 未结 6 1780
无人共我
无人共我 2020-12-11 01:38

In my application at the moment I have (as in so many other applications) an entity called Contact, which represents any person. At its most basic level this is

6条回答
  •  醉酒成梦
    2020-12-11 02:24

    I'd go with composition over inheritance in this case. If you stick with inheritance, you'll be changing classes with every promotion or demotion and every time you hire a contact or an employee leaves and becomes a regular Contact.

    It's easier just to say Contacts have Roles. You can add a Manager Role to a contact to promote it and remove the Role to fire it.

提交回复
热议问题