If I were to have interfaces like so:
public interface IAlbum
{
string Title { get; set; }
}
public interface ITrack
{
string Title { get; set; }
float Duration { get; set; }
}
What would be the best way to add a list of tracks to the IAlbum interface? What if I wanted the individual tracks to be properties and not have an exposed array of tracks?
The list of tracks could be either:
or
If you want the concrete type to expose a more concrete API, you could implement the above via explicit implementation.
You could in theory make:
but I don’t think that is a good idea.
Re exposing tracks as properties; if I understand correctly, you could do this “kind of” at runtime by implementing
ICustomTypeDescriptoron the concrete album type. But it is non-trivial and a bit messy – and it won’t help hugely unless you are using data-binding.