c++ - Class Interfaces: Basic or Complex? -


I am writing a container class for fun and education. Before writing the container classes, I had limited myself in some very basic ways: GetValue , SetValue , GetSize and < Code> resize . I did this to avoid "code spaghetti", so it's easy to debug my classroom.

However, it happened to me that the users of the classroom want to do more than just simple replacements so I added some other ways:

  change void (const std :: Size_t start, const std :: size_t end, const t value); Change Zero (const std :: size_t start, const std :: size_t end, const MyClass other); Enter zero (const std :: size_t index, const t value); Enter zero (const std :: size_t index, const MyClass other); Delete zero (Constead :: Size_T index); Remove zero (const std :: size_t start, const std :: size_t termination);   

In general, do classes provide only the most basic interface and do class users do their own work to do complex things? Or what should be made at the cost of maintaining complex content?

Classes must provide only one basic member-work (and preferably No Data!) Minimal Interface After this you can add feature methods as the non-friends non-member function. According to the interface-principle, these functions are still part of your class interface.

You have already placed the main reason for it: It makes it very easy to maintain the class; In addition to this, its "convienence" method served as a good test to implement the part. To see that you interface is quite good.

Note that the member work part of a container is usually very general and powerful, and do not care more about maintaining class invariants.

The most advanced opinion on this subject, as far as I know. It has obviously advocated Scott Meyer's "Effective C ++" (most recent third edition) and Sutter and Alexandrosco's "C ++ coding standards".

Comments