Breadth first recursion has an example of recursing through a network of objects to find them all, where a queue is used to hold unexplored paths.
Iterator interface[?] is an important part of all objects that act as containers in one way or another. It provides a consistent way to loop through that containers contents: any container should be functionally interchangable with any other for the purposes of inspecting their contents. This employes the ideas of abstract root classes[?] and abstract class.
Template class[?] talks about generators for containers. Type safety[?] breaks down when presented with generic, reusable containers that can hold any type of data. If a container only holds one specific type of data, we know any items retreived from it are of the correct type, and no type errors can occur, but then we can't reuse that container. TemplateClass follows C++'s ideas of templates, and provides a generic implementation that can create instances tailored to specific data types to enforce safety. ObjectOriented purists will find this of interest.
Aggregation pattern[?] and state vs class[?] talk about other, more present, type issues that crop up when creating containers full of subclasses of a certain type. What if one subclass doesn't do something the superclass does? Model it as state. Null-methods[?] are okay. Don't fork the inheritance to remove a feature. Similar to Introduce null object[?], but for methods.
Object oriented design heuristics[?], section 5.19, has an example of a basket that cores fruit. How could this possibly made general? Anything other than a fruit would need a //->core()// method that does nothing, requiring a base class implementing a stub //core()// to be inherited by all.
Extract a generic interface:
The article is originally from Perl Design Patterns Book
Search Encyclopedia
|
Featured Article
|