Perhaps a bit of a weird question.
I have an interface IReservable that describes behaviour to make a objects "reservable". A class which implements it must have a list of reservations, and a few methods to handle creating/removing a reservation. The interface declares a list of reservations, which is an abstract class inherited by 2 concrete classes; one for a room and one for a chair (RoomReservation & ChairReservation).
Both the room and chair classes implement IReservable, and both will always create instances of only one type (Chair -> ChairReservation and Room -> RoomReservation)
Is there a way to make it so that IReservable requires there to be a list of Reservations, but the implementation can decide the concrete Reservation?
explained in code:
public interface IReservable
{
ICollection<Reservation> Reservations { get; set; }
// Rest omitted for brevity
}
public class Room : IReservable
{
// Can I make this RoomReservation only?
public ICollection<Reservation> Reservations { get; set; }
}
public class Seat : IReservable
{
// And can I make this ChairReservation only?
public ICollection<Reservation> Reservations { get; set; }
}
It isn't necessary to do this, but I still wondered whether or not it was actually possible; since I can't find any examples of it.