I have a list of objects implementing an interface, and a list of that interface:
public interface IAM
{
int ID { get; set; }
void Save();
}
public class concreteIAM : IAM
{
public int ID{get;set;}
internal void Save(){
//save the object
}
//other staff for this particular class
}
public class MyList : List<IAM>
{
public void Save()
{
foreach (IAM iam in this)
{
iam.Save();
}
}
//other staff for this particular class
}
The previous code doesn't compile because the compiler requires all the interface memebers to be public.
internal void Save(){
But i don't want to allow the from outside my DLL to save the ConcreteIAM, it only should be saved throught the MyList.
Any way to do this?
Update#1:Hi all, thanks for the answers so far, but none of them is exactly what i need:
The interface needs to be public because it is the signature the client from outside the dll will use, along with ID and other properties i didn't bother to write in the example to keep it simple.
Andrew, I don't think the solution is create a factory to create another object that will contain the IAM members + Save. I am still thinking... Any other ideas?