What level of detail to use in an interface members descriptions?

I am extracting interfaces from some classes in .NET, and I am not completely sure about what level of detail of description to use for some of the interface members (properties, methods).

An example:

interface ISomeInterface
{
    /// <summary>
    /// Checks if the object is checked out.
    /// </summary>
    /// <returns>
    /// Returns true if the object is checked out, or if the object locking is not enabled,
    /// otherwise returns false.
    /// </returns>
    bool IsObjectCheckedOut();
}

class SomeImplementation : ISomeInterface
{
    public bool IsObjectCheckedOut()
    {
        // An implementation of the method that returns true if the object is checked out,
        // or if the object locking is not enabled
    }
}

The part in question is the <returns>...</returns> section of the IsObjectCheckedOut description in the interface.

Is it ok to include such a detail about return value in the interface itself, as the code that will work with the interface should know exactly what that method will do? All the current implementations of the method will do just that. But is it ok to limit the possible other/future implementations by description this way?

Or should this not be included in the interface description, as there is no way to actually ensure that other/future implementations will do exactly this? Is it better to be as general as possible regarding the interface in such circumstances?

I am currently inclined to the latter option.

I would advise taking a step back and looking at what you’re trying to achieve.

What does the XML documentation give you? XDoc Documentation? Think about what you want to see in that document. Intellisense? Think about what you want to see when someone is using that method from the interface. Or are you just doing it because you think you should? If so then stop it, you’re wasting valuable time.

Already I can see that the method name doesn’t match what the method does. And that’s probably the reason you’re having to ask this question.

Should the method really be named IsObjectCheckedOutOrNonLockable()? Or does IsObjectNonLockable() implicitly include “checked out” on the objects you currently have implemented? Or is there a better description that covers all those conditions?

Does renaming the method make it more obvious what you should put in the XML documentation and more obvious what is expected of future implementations?

2

Be as specific as you can describing how interfaces should look and behave. There is no use having an interface method whose return value is ambiguous – it breaks the whole notion of interfaces. Just because few languages offer the ability to enforce all the requirements and intentions of the interface, such as the precondition and postcondition support in Eiffel, it should not stop you communicating expectations to both callers and implementers.

An interface defines an API and a protocol. I.e., two interfaces can have the same API, but have different protocols. Method A in Interface 1 can do one thing and method A in interface 2 can do a completely different thing.

An interface should only enforce an API (by the compiler) and a protocol (by the developer); it shouldn’t enforce or even hint at any implementation details.

Your problem lies in the approach of “extracting the interface” from a concrete class.
You (and your code) already know (and possibly care) about the actual implementation.

Instead of doing that, try refactoring client code to use a hypothetical interface that looks right and its goal is self-explanatory by its use. Then, and only then, adjust your concrete class to implement that interface.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật