Sponsored Link •
Bill Venners: These two things, minimal and complete,
seem to be in tension. In your Effective C++ justification of minimal
interfaces, you illustrate that multiple methods that do the same exact thing,
ruminate, are confusing. But striving for a minimal interface
also seems to discourage the adding of gratuitous bells and whistles.
Scott Meyers: Yes.
Bill Venners: I guess I'm going back to the question, how do I know if the client really needs a particular method? How do you find that sweet spot that is both minimal and complete?
Scott Meyers: Finding the sweet spot is harder. If you follow my design guideline, most classes will probably be harder to use than you would like. Many convenience functions that people want won�t be there. If you want to have a nicely rounded class interface that does hit the sweet spot, you will almost certainly have some ancillary member functions. The ancillary functions will let people do things they could have done by making a bunch of calls through the public interface. Instead, they just call a single function that wraps the bunch of calls into a single function name.
Bill Venners: But that's not the minimal and complete sweet spot. That's the almost minimal, a little more than complete, but user- friendly spot.
Scott Meyers: Minimal and complete applies to the member functions. In that particular item, I'm talking about what you make member functions. I advocate that you determine what should be a member function by shooting for the minimal complete set.
However, you will probably want to offer clients a greater degree of functionality. I will call this greater degree of functionality, which includes all the member functions plus whatever non-member functions you provide for convenience, the interface to the class, because that is the set of functionality you are offering them. When you're shooting for the sweet spot, you really want a class that has a convenient interface.
Bill Venners: I see. Where are those non-member functions? Are they global functions that take this type of object as parameters?
Scott Meyers: Exactly. They are non-member functions. I actually wrote an article for CUJ (C/C++ Users Journal) a couple years ago. I suggest putting the non-member functions in the same namespace as the class, so they are also not global. I suggest using the namespace to package the non-member functions with the classes to which they are associated.
Effective C++, Second Edition, by Scott Meyers is at Amazon.com at:
More Effective C++, by Scott Meyers is at Amazon.com at:
Effective STL, by Scott Meyers is at Amazon.com at:
Effective C++ CD, by Scott Meyers is at Amazon.com at:
Scott Meyer's website contains links to many publications, presentations, books, and other information from Scott:
Images of Persephone, the best dog in the world: