title: Manage Complex Relationships Between Objects
body: <p>I am trying to understand how to model 'complex' relationships between two objects when using object oriented programming.</p>
  
  <p>I can understand how to manage simple relationships, such as when there is a 1:1 or a 1:M mapping between objects, ie;</p>
  
  <p>1:1 Relationship</p>
  
  <pre><code>public Car
  {
     public string Manufacturer { get; set; }
     public string Model { get; set; }
  
     public Engine Engine { get; set; }  // 1:1 relationship here
  }
  
  public Engine
  {
     public int NumberOfCylinders { get; set; }
  
     public Car Car { get; set; } // 1:1 relationship here
  }
  </code></pre>
  
  <p>1:M Relationship</p>
  
  <pre><code>public Father 
  {
      public string FullName { get; set; }
  
      public List&lt;Child&gt; Children { get; set; } // 1:M relationship here
  }
  
  public Child
  {
     public string FullName { get; set; }
  
     public Father Father { get; set; }  // 1:M relationship here
  }
  </code></pre>
  
  <p>.. but the question is, how do I manage the relationship between two objects when the relationship is more complex?</p>
  
  <p>For example, lets assume an example when there is a task that can be completed by either Joe <em>OR</em> John (i.e. either person can complete the task). How would I model this?</p>
  
  <pre><code>public Task
  {
     public string Description { get; set; }
  
     // what do I put here?
  }
  
  public Person
  {
     public string FullName { get; set; }
  
     // what do I put here?
  }
  
  var joe = new Person() { FullName = "Joe" };
  var john = new Person() { FullName = "John" };
  var task = new Task() { Description = "Task that can be completed by either Joe or John" };
  </code></pre>
  
  <p>I am sure that there must be a common pattern that can be used to model situations like these, but I have been unable to find a solution!</p>