title: soft delete in DDD
body: <p>I have a scenario where a given entity may be marked for soft delete or a hard delete based on some logic when a user requests delete. <br/>
  <br/>
   Approaching this problem from DDD paradigm, i see some issues :- DDD proposes use of Repository object for all persistence related stuff where the domain layer just defines such repo interface (containing typical methods like store, remove, find) and the infrastucture layer containing the actual implementation. Given that, for my problem here then , the logic that decides whether to do a soft delete or not belongs domain layer, how is it possible to contain the logic in domain layer in such a way where the safety that any delete request by any other layer is channeled through this logic before coming to point of actually calling a delete on RepoImpl that actually removes the entity from underlying store ??.<br/>
  <br/>
  &nbsp; Even if I have a domain service having a method like <code>void removeEntity(Entity ent)</code> , the fact that I have to have a public method on my repo interface called <code>void remove(Entity ent)</code> defeats the purpose because I can't enforce that <code>removeEntity</code> of service layer is to be called always instead of <code>remove</code> on repo and RepoImpl needs to have a remove method to give implementation of removal of an entity.
  <br/><br/>
  <em>Proposed Solution</em><br/>==============
  <br/>
  &nbsp; I have this idea that looks rather contrived, let's say the Repo interface has an abstract implementation that has provides a final <code>public void remove(Entity ent)</code> , the abstract implementation can do this logic to determine if its a soft or hard delete. If its a soft delete its actually an update of the entity with proper flags set , so it calls <code>this.store(ent)</code> otherwise it wraps the entity in a <code>DeleteEvent</code> class</p>
  
  <pre><code> public class DeleteEvent&lt;T&gt;{
     //parametrized for Entity
    private T ent;
     DeleteEvent(T ent){
       this.entity = ent;   
  }
  
   public T getEntity(){
     return this.entity; 
  }
  }
  </code></pre>
  
  <p>Note the non-public, package access  constructor, objects for this class can only be constructed from within domain layer, so the other remove method on the RepoImpl is <code>void removeFromStore(DeleteEvent evt)</code>  RepoImpl gets entity from this sealer/holder and implements the removal process.<br/>
  This although looks like can work is rather quirky/hacky, is there a cleaner way to achieve the same ??</p>