Next: Specify Dependencies
Up: C++ Design Issues
Previous: Find Classes
Refine classes by specifying the sets of operations on them. Naturally, it is
not possible to separate finding the classes from figuring out what operations
are needed on them. However, there is a practical difference in that finding
the classes is focusses on the key concepts and deliberately deemphasizes
the computational aspects of the classes, whereas specifying the operations
focusses on finding a complete and usable set of operations.
The strategy in considering what functions are to be provided may be the
following:
- Consider how an object of the class is to be constructed, copied (if at all)
and destroyed.
- Define the minimal set of operations required by the concept the class is
representing. Typically these operations became the member functions.
- Consider wich operations could be added for notational convience. Include only
a few really important ones. Often these operations became nonmember functions.
- Consider wich operations are to be virtual, that is, operations for which the
class can act as an interface for an implementation supplied by a derived
class.
- Consider what commonality of naming and functionality can be achieved
across all the classes of the component.
Motto: Try to minimalize your interface. You can allwais extend your interface,
but almost never narrow it. Note that minimalism requires more work from the
designer, rather than less. When choosing operations, it is also important to
focus on what to be done rather than how it is to be done.
Classification of operations:
- Foundation operators: constructors, destructors and copy operators.
- Inspectors: operations that do not modify the state of an object.
- Modifiers: operations that do modify the state of an object.
- Conversions: operations that produce an object of another type based
on the value (state) of the object to which they are applied.
- Iterators: operations that allow aaccess to or use of a sequence of
contained objects.
Next: Specify Dependencies
Up: C++ Design Issues
Previous: Find Classes
Porkoláb Zoltán
2001-09-03