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

后端 未结 6 1781
无人共我
无人共我 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 would personally have a base class with all the basic things in it and a list of roles.
    Each role has it's own properties and functionalities.
    The advantages are two fold:

    • It's easy to give or take a role to/from a person
    • It will allow your people to have multiple roles without you having to make 'combination classes'

    If you go with single inherritance going with inherritance will soon render you with classes like "ManagerProgrammer", "ProgrammerStockManager", "ProgrammerSupport"

提交回复
热议问题