That is a very logical next step, but this example is limited to only preventing use of the OuterClass' collections,
Richard Deeming wrote:prevent the user from creating new types that implement the interface outside of your assembly?
In this example, the end user is free to create as many Dogs and Cats as they can afford
p.s. the code gets more interesting when you define an encapsulated instantiator like this:
internal T NewInstance<T>(params object args)
where T : class, ISomething1
var ttype = typeof(T);
ISomething1 instance = null;
instance = (T) Activator.CreateInstance(ttype, args);
return (T) instance;
}Which is, of course, only one way to handle instantiation; I tend to avoid 'Activator.CreateInstance for reasons I am sure you are aware of.
Returning to the "big picture:" what strategies do you use to increase the encapsulation of classes that maintain collections of mixed types ?
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch