Library Organization in .NET

I’ve written a .NET bitwise operations library as part of my projects (stuff ranging from get MSB set to some more complicated bitwise transformations) and I mean to release it as free software. I’m a bit confused about a design aspect of the library, though.

Many of the methods/transformations in the library come with different endianness. A simple example is a getBitAt method that regards index 0 as the least significant bit, or the most significant bit, depending on the version used.

In practice, I’ve found that using separate functions for different endianness results in much more comprehensible and reusable code than assuming all operations are little-endian or something.

I’m really stumped regarding how best to package the library.

  • Should I have methods that have LE and BE versions take an enum
    parameter in their signature, e.g. Endianness.Little,
    Endianness.Big
    ?
  • Should I have different static classes with
    identically named methods? such as MSB.GetBit and LSB.GetBit

On a much wider note, is there a standard I could use in cases like this? Some guide? Is my design issue trivial? I have a perfectionist bent, and I sometimes get stuck on tricky design issues like this…

Note: I’ve sort of realized I’m using endianness somewhat colloquially to refer to the order/place value of digital component parts (be they bits, bytes, or words) in a larger whole, in any setting. I’m not talking about machine-level endianness or serial transmission endianness. Just about place-value semantics in general. So there isn’t a context of targeting different machines/transmission techniques or something.

As in most instances of the design problem, the solution should be based on intended usage and context, instead of any alleged absolute.

You need to establish your requirements. What do you use the library for? What is your target audience for this library?

If the intended usage is to mix little-endian logic together with big-endian logic, then it’s beneficial to add an extra argument for each method, such as Endianness.Little, just like you suggested.
I wouldn’t suggest a clone for each method, as that would grow rather quickly, and with today’s IDEs and auto-completion it would be a visual disturbance, and also would have a (probably negligible) impact on compile time.

However, if you intend to use the library for different platforms, but on each one pick one scheme, then you’re probably better off with passing an Endianness strategy to the constructor of a class that has higher level methods.

If you want to get the best of both worlds, at the expense of simplicity, you can pass a strategy in a constructor, and accept an optional strategy in each method, which defaults to the one provided in the constructor.

4

I agree Yam that it depends on your usage of the library. Another interesting arrangement, if you’re not going for insane levels of performance could be to create a class that holds both answers. GetBit will then return an instance of this class, with two properties presenting the results.

public class BitWiseResult 
{
  public <type-goes-here> MSB { get; set; } 
  public <type-goes-here> LSB { get; set; } 
}

public BitWiseResult GetBit() ...

This arrangement will be best used if you need to use both results interchangeably. It has the advantage of giving you the right result in the exact place where you need it, as opposed to changing a possibly distant function call or class instantiation.

1

If your library users will stick with one Endianness in their application I would use an abstract factory.

// setup
var factory = new LittleEndiannessFactory();

// usage
var algo = factory.CreateSomeAlgo();

Else you’ll probably want them to specify the endianness in each method call.

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