CS 4448 - Fall 1998
Object-Oriented Programming and Design
Talk 9.2
by
Peter Alber
Usability and Class Library Design
by
...
Overview:
In todays world
programmers are expect to do more development in less time. This has
created a need for code that is easy to understand, and has a small
learning curve. Below are a few simple guidelines to increase the
usability of your code.Keep it Simple
Have as few classes, methods, and parameters as
possibleKeep methods private if possibleGroup
methods into a number of smaller, separate class
libraries.Help Users be
Productive Quickly
Minimize the
number of classes that need to be subclassed before they can be
used.- It can interrupt the flow of
development
- For classes that must be subclasses, minimize the
number of methods that need to be overridden.
Identify the Tools for a
Task
Label everything clearly
that is intended for internal useClearly identify classes
that must be subclassed. (i.e. label advanced, or
implementation)Use
Real-World Knowledge to Speed Understanding
Understandable naming conventions for classes and
methods.Use natural-language-syntax in
naming. (i.e. "reverse English")Name classes with a
nounName methods with a verb
(i.e. file->print())Avoid using
abbreviationsBe
Consistent
This will reduce
learning curve in understanding an entire class library.Put
classes in header files that make sense.Can be beneficial to
use class naming prefixes. But be CONSISTENT!!!Consistency in
"Accessors" (i.e. int getVal() and void setVal(int x)
)Dont Make Things
Almost the Same
Dont
override an operator to do completely different things on different
data typesMake keywords completely unambiguous and
understandableAn example in C++
- aStream>>doc; // Extracts data from aStream and
puts it into doc
- aSteam>>dec; // Special keyword to
convert stream into decimal format
- aStream>>decimalMode
would have been more understandable
Design to Prevent User
Errors
Use #ifndef, #define,
#endifPassing and Returning a reference instead of a pointer
if possible can avoid certain errors.Make completely clear
who is responsible for destroying memory in non-garbage collection
languages.Default Values
or Behaviors
If simple is better,
being able to call a function with no parameters is the best method to
have.Make a default behavior for abstract classes, or throw
an error if it hasnt been created.
Copyright © University of Colorado. All rights reserved.
Revised: Novemeber 10, 1998