Is it bad practice to use interfaces for my properties considering I want to encapsulate them?
public class Order
{
private readonly ICollection<OrderItem> _orderItems;
public IReadOnlyCollection OrderItems => _orderItems; // not possible without ToList
}
There's no easy way to expose it as there's no way to convert to IReadOnlyCollection
or IEnumerable
from ICollection
without using ToList
first which involves copying entire collection.
Should I define it as:
private readonly Collection<OrderItem> _orderItems;
or
private readonly HashSet<OrderItem> _orderItems;
or
private readonly List<OrderItem> _orderItems;
instead?