I have two models, Ship and Sector, where Ship has a property named Location which is an instance of the Sector class, and Destination which is another instance of the Sector class. Considering encapsulation the ship itself should be responsible for updating these properties, so I made a Move() method that calculates how much progression the ship made and should update the Location property accordingly. If the new location is different from the destination (there are sectors in between and the ship is halfway), how do I get a reference to the instance of that Sector?
public class Ship
{
public Sector Location { get; set; }
public Sector Destination { get; set; }
public void Move()
{
// some magic happens here. Now I would like to update the Location.
}
}
I use Entity Framework and a repository pattern. So I have a SectorRepository and a ShipRepository that both implement the following interface.
public interface IRepository<T>
{
T Get(int id);
T Get(Expression<Func<T, bool>> predicate);
void Add(T entity);
void Remove(T entity);
List<T> GetAll();
List<T> Search(Expression<Func<T, bool>> predicate);
}
I could make an instance of SectorRepository in the Ship model, but that feels like Tight Coupling, which I would like to avoid if possible.