Interface and its availability

I was asked a question in an interview about interfaces. I'm not sure if this is really possible. See Question below.

There are 3 interfaces A, Band C. Ainherits from interfaces Band C:

public interface A : B,C
{

} 

We need to make sure that the users of these interfaces can not be used B, and Ceither directly or independently and must use only A.

I could think of the following scenarios:

  • Make internal interfaces Band C. But I do not see any real use, since I could directly identify all the members in A.
  • Do Band Cprivate interfaces. But how can I do this? In addition, I saw on the following MSDN link that Bthey Cshould be at least as accessible as A: http://msdn.microsoft.com/en-us/library/aa664578%28v=VS.71%29.aspx .

Is there a way to do this, or is the question itself wrong?

+3
source share
3 answers

What you ask for would be a violation of the Liskov Principle of Replacement .

If Aimplemented Bin this way, it should always be used directly as B. Attempting to prevent this will violate one of the basic requirements of object-oriented design.

, , " , ..." .

+5

, . B, C, , . -, B C A. ( , A ).

, A, .

+1

, B C A.

B C, - A, , B C, A, , A.

, !

0

Source: https://habr.com/ru/post/1788752/


All Articles