Should this property be part of my object interface?

I have a property called "IsSecureConnection", which is part of my object interface. This makes sense for most implementations of the interface, however in some implementations I would like to make the ReadOnly property.

Should I ignore this property from the object interface, even if it is required for all implementations (although sometimes this is slightly different)?

Thank!

+3
source share
4 answers

It really depends on what is most readable to your customers. I can present several options:

1) , , , VB.NET :

interface IObject {
    bool IsSecureConnection { get; }
   // ... other interface definitions //
}

interface ISecurableObject : IObject {
   new bool IsSecureConnection { get; set; }
}

2) :

interface IObject {
    bool IsSecureConnection { get; }
   // ... other interface definitions //
}

interface ISecurableObject : IObject {
   void SetConnectionSecurity(bool isSecure);
}

3) , , false:

interface ISecurable {
   bool IsSecureConnection { get; }
   bool TrySecureConnection();
}

4) :

interface ISecurable {
   bool IsSecureConnection { get; set; }
   bool SupportsSecureConnection { get; }
}

, IMO, . , , - , , 3. , , ( ). , TrySecureConnection, , , .

, - 1 , , , IObject ISecurableObject. . 2 , / . , , ( 2), , - .

4, IMO ( - . IO.Stream) , . 90% , SupportsSecureConnection. , IsSecureConnection = true, , , IsSecureConnection.

+3

getter .

public interface Foo{
  bool MyMinimallyReadOnlyPropertyThatCanAlsoBeReadWrite {get;}
}

, ; , . .

+6

: :

public interface ICanBeSecure
{
    bool IsSecureConnection { get; }
}

public interface IIsSecureable : ICanBeSecure
{
    bool IsSecureConnection { get; set;}
}
+5

. , , .

public interface IFoo {
   bool SecuredConnection{ get; }
}

public interface ISecurableOptionFoo: IFoo {
   bool SecuredConnection{ get; set; }
}
+3
source

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


All Articles