interface protection boundaries.. internal/friend.. OOD advice
Here's a tricky one. I've got a Management class that has methods that
return references to an interface called, for this case, IComp. Internally,
the Management class scans its own internal registration information to figure
out which assembly and class to actually instantiate that implements the
IComp interface. Upon instantiation, it returns a reference to this new instance.
Ok.. everything's good so far.
Each class that implements IComp has its own configuration that is maintained
by the Management class. At runtime, and consumer of IComp needs the ability
to query that interface for its configuration (likely some Xml DOM doc),
however it needs readonly access. That's simple enough to enforce through
the interface declaration. However, the Management class needs to be able
to update the configuration for a given instance of IComp at runtime, therefor
the Management class needs write access to the "configuration" member of
the IComp interface. It doesn't have to be a property; it can be any type
of accessor. BUT, when designing an interface, one cannot declare an interface
to be public and to contain any private, protected, or internal/friend members.
That makes sense. But, the problem is, how do I enfore read-only access to
members of an interface, but allow write access to that same member from
1 designated source? I can change the interface to be an abstract base class,
but that won't work because having everything descend from IComp is just
not possible for this project.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center