Solution 1 explains the implementation of interface using
implicit implementation where
public modifier is essentially required (which you missed). However, this is only good if you really need to use this members in some other ways, not only through the interface (and it's best to avoid, in most cases).
In other cases, it's better to use the
explicit implementation of the interface. It gives the access to the implemented member only throw the interface reference, which is clearer. Here is how:
public class Member : IModel { }
public class MemberFactory : IFactory<Member>
{
Member IFactory<Member>.Get(int id)
{
}
}
I also want to add that
MemberFactory
itself can better be generic. If some functionality depends on the specific generic types, you can implement all common functionality (common to generic parameters), make it abstract, and override the specifics in derived classes. This is how:
public interface IModel { };
public interface IFactory<Member> where Member: IModel { Member Get(int id); }
public class Member : IModel { }
public class MemberFactory<Member> : IFactory<Member> where Member: IModel {
Member IFactory<Member>.Get(int id) {
return default(Member);
}
protected abstract void Something(Member member);
}
—SA