Interface Size and Intuitiveness

It's generally wise to keep the interfaces of new classes small whenever possible. Why? Because interfaces are the aspect of OO design that both class builders and class users have to worry about. A large interface ends up causing more work for everybody, gives everybody more to remember, and opens a wider door for bugs to slip through.

If there seem to be far too many methods in a new class, there are at least two ways to think about the problem.

On the one hand, an apparently excessive number of methods might indicate that the role of the class is poorly defined. Perhaps the class's job doesn't make all that much sense; it has been given too much or too little to do. There may be a better way to divide the labor ...

Get Sams Teach Yourself Ruby in 21 Days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.