foobar
foobar

Reputation: 11

Interface for Saving/Loading to a Collection

I want to create a simple general purpose interface to Save data to a collection and Load data from a collection. Which of the following (or none) is most appropriate?

The collection could have many levels and these details would be hidden behind the interface.

Option A.

public interface ISaveToCollection<T,U>
{
    void Save(T element);
    U Data { get; }
}

public interface ILoadFromCollection<T,U,V>
{
    U Load(T index);
    V Data { get; }
}

Option B.

public interface ISaveToCollection<T>
{
    void Save(T element);
}

public interface ILoadFromCollection<T,U>
{
    U Load(T index);
}

public interface IHoldData<T>
{
    T Data { get; }
}

Option C. None of the above (along with reasons and an alternative).

Upvotes: 0

Views: 414

Answers (1)

Riad Baghbanli
Riad Baghbanli

Reputation: 3319

Please familiarize yourself with ICollection interface, it already has methods you are trying to write: https://msdn.microsoft.com/en-us/library/92t2ye13%28v=vs.110%29.aspx

Upvotes: 2

Related Questions