M
Magnus Lidbom
Magnus Lidbom said:On Mon, 9 Feb 2004 20:45:50 -0600, "Daniel O'Connell [C# MVP]"Unfortunatly, there are alot of situations where an explicit implementationYes, I know what the purpose of the feature isIt is also useful
for the ability to implement an internal interface. But neither of
these uses would replace an implicit implementation with an explicit
one. My point was that such a replacement is a fundamentally flawed
design that makes it impossible, even in theory, to know in a generic
fashion how to call the method in order to access the correct method.
There simply is no correct method. Given this, I wouldn't cast to an
interface unless it was emplicitly implemented for the class in
question. Of course, I'd have no choice in that situaton![]()
may have been chosen. I try to work with interfaces as interfaces(actually
try to never see anything but the interface, but factories can't always
solve the problem). Most of the time I work with interfaces explicitly,
trying to avoid concrete types(I do alot of plugin\loosely coupled systems).
So my casts to interfaces are done at a rather low level, usually casting
from object using as. It works fairly well, IMHO.
I've been arguing against using unnecessary casts. For a plugin
architecture, there is no choice, that I know of, somewhere you will
have to cast to the interface that the plugins implement. As long as
this is done only in the appropriate part of the subsystem that sets
up the plugins, I see nothing wrong with it.
I think readonly would fit here better. readonly const MyStruct myInstance.
readonly already restricts access to a reference to only a constructor for
fields, in a method it could be limited to declaration or perhaps a readonly
block:
readonly
{
readonly const MyStruct myInstance;
myInstance = new MyStruct();
}
This isn't nessecerily the same thing, more complicated structures like
point have fields that can be set, properties and methods that can be
called. Some of these properties and method are const, some are not. In
these cases changing the entire structure is a different matter than
changing certain fields.
But that's my point, there is no meaningful difference. The variable
is the instance There are no references, except when using ref or out,
to value types. If const above means no field may be modified, then it
also means that the entire instance may not be replaced, because that
would replace all the fields. The variable, the instance, and the
instance's fields, are all one and the same, they occupy the same
memory. Accordingly, you only need one. Readonly or const.
<snip>
/Magnus Lidbom