Can the following Domain Entity contain logic for creating/deleting other entities?

Posted by user702769 on Programmers See other posts from Programmers or by user702769
Published on 2012-10-04T18:58:14Z Indexed on 2012/10/04 21:52 UTC
Read the original article Hit count: 243

a) As far as I understand it, in most cases Domain Model DM doesn't contain code for creating/deleting domain entities, but instead it is the job of layers ( ie service layer or UI layer ) on top of DM to create/delete domain entities?

b) Domain entities are modelled after real world entities. Assuming particular real world entity being abstracted does have the functionality of creating/deleting other real world entities, then I assume the domain entity abstracting this real world entity could also contain logic for creating/deleting other entities?

class RobotDestroyerCreator
{
         ...
         void heavyThinking()
         {
                  ...
                  if(...) 
                        unitOfWork.registerDelete(robot);
                  ...

                  if(...)
                  {
                         var robotNew = new Robot(...); 
                         unitOfWork.registerNew(robotNew);  
                  {
                  ...
          }
}

Thank you

© Programmers or respective owner

Related posts about design-patterns

Related posts about domain-driven-design