c# naming – What are common conventions for a suffix to distinguish between read-only and writable interfaces [closed]

Assume an interface that allows queries on a spatial tree

public ISpatialTree
{
    int FindChildIndex(Vector point);
    bool IsLeaf { get; }
    ICollection<ISpatialTree> Children { get; }
}

and another one that allows changing the tree:

public ISpatialTreeWriter : ISpatialTree
{
    void Add(Vector point);
    bool Remove(Vector point);
    void Clear();
}

I am looking for a name to denote the writeable interface. Ideally it would be reasonably short and readable word. It’s not only for this example, but I would like to use a convention for all code in the project because this is a common case.

Does anyone know of a good convention for this problem? What conventions are used in other projects?

Words that were discussed include Writer (ambiguous, often used in other contexts), Mutator (confusing), Rw (unreadable, not a word).

A good solution would be a single word, not longer than 6-8 letters and that makes it obvious that this is the writer interface.

7

Writer and Mutator are a bad choice because they imply mutating something else. If you change the object itself, the proper forms are Writable and Mutable.

If you have a readonly interface but the underlying object can be changed through another interface, that object isn’t immutable. This implies that mutability vs. immutability is not the distinction you want to make here.

So only ReadOnly, ReadWrite or Writable remain. Since you don’t have WriteOnly access at all you don’t need to distinguish ReadWrite from WriteOnly. ReadWrite isn’t a proper word, so I’d rather go with the simpler Writable.

Following the convention of the existing collections in .NET, the appropriate choices would be IReadOnlySpatialTree and ISpatialTree, where the latter is writable.

If most of your code is only reading and write access is the exception, you could deviate from this convention and use ISpacialTree as the readonly interface and IWritableSpacialTree as the writable interface.

4

I would suggest that you specify a read-only interface style, such as:

interface IReadOnlySpatialTree
{
}

and then the writeable interface extends this with its name only, ie.:

interface ISpatialTree : IReadOnlySpatialTree
{
}

You will rarely use a writeable interface without also needing the readonly part. If you’re not careful you’ll end up with at least 3 interfaces for every type (readonly/ writeonly and readwrite), which isn’t particularly useful and is a waste of energy to maintain.

Having a readonly interface is useful, as these methods are presumably pure, which simplifies caching and other aspects. It also means one can ensure that writes do not happen unintentionally. However, for a writeable interface, being also to read also doesn’t really matter- the readonly interface doesn’t have side-effects.

There is the rather weird method List<T>.AsReadOnly in the .NET framework, as MS didn’t consider readonly in the first place.

2

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