Not all interface members will be implemented

Is this correct when speaking about the general fact that some “interface members” are not implemented for certain classes simply because they are not used in certain circumstances, so you throw an error into the body of the method?

For example, you can say that I am creating an IAPIAuthentication interface, which is a server as a contract for classes that will perform authentication requests by a third-party API, such as Facebook, and others that we will implement later.

Thus, my IAPIAuthentication interface will have the following properties:

// The URI that the auth HTTP Request will go to (minus any querystring values, this is just the base)
AuthenticationURI (property)

// unique ID for your API account with whatever API you are using (Facebook, Picasa, whatever)
ClientID  (property)

// unique secret code also obtained when you sign up for an API account and used in auth calls
ClientSecret (property)

// a confirmation code sent back from the 
AuthenticationVerificationCodeID (method)

// a boolean property set to true if an AuthenticationVerificationID was received back after an Auth request
AuthenticationWasSuccessful (property)

// sends the actual HTTP Request to the specified Uri
SendRequest()

Good, therefore, in many cases, other APIs require the same information during their auth process (e.g. PhotoBucket, etc.).

, , API-, , , . API- NVP, , , , API , 90% , .

, , FacebookAuth, . . , , , , , , / -), , . , , , , . , , .

, :

  • , , API- ?

  • , , , .NET- , - . ... , ( ). "" , "" , 100%? , , , 100%. , ... API ... ... , .

- , ... , , . . , (, yada yada), , , . ... , . , . , API? , , ...

, . , . , , .

+3
4

, .

, , , .

, , , , , . - .NET BCL, ICollection , , Add, Remove Clear. , ICollection IsReadOnly, , .

, NotSupportedException, NotImplementedException, .

+15

, , , . , / , . - , :

  • "", . , .
  • , , . , .
  • ( ).
  • # 1 /, , ( ).
  • # 2 , .

№1 . , try/catch, . , -, , . , , , - , NotSupportedException - .

№ 2 , , . , , , №1 - .

№ 3 : " , ". . , , , ( ) . "" , .

№ 4 , , . -, - NotSupportedException , , , . , , , . - , , ( ), .

№ 5 # 2 partitiong - , , . , . , , , . , - SupportedCapabilities. , , . , , № 2.

: " ". , , , .

+3

, , NotSupportedException, . , .

public interface IExample
{
    void Add(int id);
    void Remove(int id);
    bool Contains(int id);
}

public class ReadOnlyExample : IExample
{
    private readonly HashSet<int> _ids;

    public ReadOnlyExample(IEnumerable<int> ids)
    {
        _ids = new HashSet<int>(ids);
    }

    public bool Contains(int id)
    {
        return _ids.Contains(id);
    }

    void IExample.Add(int id)  // explicit interface implementation
    {
        throw new NotSupportedException("This example is read-only!");
    }

    void IExample.Remove(int id)  // explicit interface implementation
    {
        throw new NotSupportedException("This example is read-only!");
    }
}
+2

. , , getters/setters, , . :

public string ClientID
{
    get
    {
        throw new NotSupportedException();
    }
}
+1

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


All Articles