jeudi 19 octobre 2017

Interface naming convention/pattern - readonly view of class properties

Is there a naming convention (or a pattern) for when you have an interface that exists purely to expose some properties for viewing:

public interface IFooInfo
{
    // Contains a few properties that will be exposed outside of the namespace
    bool item1 { get; }
}

internal interface IFoo : IFooInfo
{
    // Allows item1 to be set. Also contains a method that shouldn't be accessed elsewhere
    new bool item1 { get; set; }

    bool method1();
}

internal class Foo : IFoo

Considering the above, I would like to know if there is an existing naming convention (for the interface names) or an existing pattern that makes it clear what the interfaces are for, and how to use them. My actual classes/interfaces are much more complex than the above and I am struggling to make something that gives another developer a chance of quick and easy understanding.

To be clear:

Elsewhere, in another class, a public instance of IFooInfo is created, allowing the next layer of abstraction to see the value of item1 but not change it.

It has a private backing field, which is an instance of IFoo (or Foo). Here the class members and methods can be played with at will.

Aucun commentaire:

Enregistrer un commentaire