Trying to Understand Compiler Error CS0011

  • Thread starter Thread starter David Elliott
  • Start date Start date
D

David Elliott

I have the following setup:


Project_1 Library
===========================
public interface IDataStorable
{
}

Project_2 Library
===========================
Added a "using <namespace>" to Project_1 namespace
Added reference to Project_1
public class CommonDataStorage : IDataStorable
{
private IDataStorable fileSystem = null;
}


Project_3 Library
===========================
Added a "using <namespace>" to Project_2 namespace
Added reference to Project_2
public class DocProcWSApi
{
static private CommonDataStorage dataStorage = null;
}


I found the error "Compiler Error CS0011" on MSDN
http://msdn.microsoft.com/library/d...n-us/cscomp/html/vcerrcompilererrorsc0011.asp

But don't quite understand why this is a problem. Project_1 and Project_2 compile just fine.
In order to get Project_3 to compile I added a reference to Project_1. This seems quite wrong.
Project_3 shouldn't have to know the internals of Project_2. Project_2 should handle any
referencing to Project_1, which it does.

Is there a better explaination than "That's jus the way that it is"?
Why isn't this more of a problem with the rest of the framework?

Thanks,
Dave
 
David Elliott said:
I have the following setup:


Project_1 Library
===========================
public interface IDataStorable
{
}

Project_2 Library
===========================
Added a "using <namespace>" to Project_1 namespace
Added reference to Project_1
public class CommonDataStorage : IDataStorable
{
private IDataStorable fileSystem = null;
}


Project_3 Library
===========================
Added a "using <namespace>" to Project_2 namespace
Added reference to Project_2
public class DocProcWSApi
{
static private CommonDataStorage dataStorage = null;
}


I found the error "Compiler Error CS0011" on MSDN
http://msdn.microsoft.com/library/default.asp?url=/library/
en-us/cscomp/html/vcerrcompilererrorsc0011.asp

But don't quite understand why this is a problem. Project_1 and
Project_2 compile just fine. In order to get Project_3 to compile I
added a reference to Project_1. This seems quite wrong. Project_3
shouldn't have to know the internals of Project_2. Project_2 should
handle any referencing to Project_1, which it does.

Project_3 is entitled to know about the interface that
CommonDataStorage implements - that's why you're getting the error, I
believe, and I think it's fairly reasonable.

The interfaces a class implements aren't internals - they're part of
the public interface of that class.
 
Dave said:
I would agree that Project_3 is entitled to know about the interface.

Project_2 has a reference to Project_1.
Project_3 has a reference to Project_2.
The reference to Project_1 from Project_3 should be transitive.

Project_3 shouldn't be REQUIRED to reference Project_1, unless
explicitly using an object of type IDataStorable. None of the
Methods in Project_2 take a parameter or return IDataStorable.

I should be able to call into the Methods without knowing that
the class implemented an interface. Project_2 should in all
reality be a black box.

No, because the fact that it *does* implement the interface is public
knowledge. Try building documentation which hides it, for a start...

It's just as much part of the public interface (IMO) as the base class
is - would you expect to be able to use a base class which the client
didn't know anything about>
 
Back
Top