Well, that’s what I would like to do.
Class Container<T>
{
T contained;
public void ContainObject(T obj)
{
contained = obj;
if()
{
IContainableObect c = (IContainableObject)obj;
c.NotifyContained(self);
}
}
}
interface IContainableObject
{
public void NotifyContained(Container<REPLACE_THIS>);
}
Class ImplementingType : IContaiableObject
{
public Container<ImplementingType> MyContainer;
public void NotifyContained(Container<ImplmentingType> c)
{
MyContainer = c;
}
}
Class Main
{
public static void Main(args)
{
ImplementingType iObj = new ImplementingType();
Container<ImplementingType> container = new Container();
container.ContainObject(iObj);
}
}
Basically, to summarize the above example, I have a common wrapper type of type T. I would like this wrapper type to notify everything that it contains that it is contained (with a copy of itself!) IF the contained object implements a certain interface (this bit i know how to do it)
But it gets complicated! What for? Good, because the general type of the container must be of type.
Remember this important line?
If REPLACE_THIS is an IContainableObject, then all interface executors should use IContainerObject, not the name of the implementation class in the NotifyContained method.
Using OptioningType as a container type inside an interface is even worse, for obvious reasons!
, : , REPLACE_THIS , ?