When polymorphism is possible, allow the caller to pass in a variable (via reference) for the result of a function rather than creating and returning a result yourself. For example, if you make a call that returns a collection of things, it is better to let the caller specify the kind of the collection (by supplying it) rather than creating a collection and passing it back. By specifying the argument type as TCollectionOf<>
&
(or a subclass, if you need to be more restrictive), you give the caller flexibility to choose the appropriate collection type. It also eliminates a potential source of storage leaks. However, beware of assignment to these parameters: unless the assignment operator is virtual, such assignments
might slice.
[Contents]
[Previous]
[Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.
Generated with WebMaker