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

后端 未结 6 1774
无人共我
无人共我 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:33

    As long as your business model matches your domain, you're doing the right thing.

    However, it sounds to me like you should have something like:

    Manager Promote(Employee employee)
    {
       var manager = new Manager();
       //promote your employee to a manager here
       return manager;
    }
    

    inside some workflow process of some sort.

    In regards to NHibernate, it sounds like you're mixing your ORM logic with your business domain. Promoting an Employee to a Manager is a business domain construct, and as such belongs in your business model. However, how NHibernate maps your Employees and your Managers into your DB has nothing to do with your business model, except for how to map them over. This definitely doesn't have anything to do with how to promote an employee to a manager, though.

提交回复
热议问题