Abstract
In this paper, we describe and compare techniques that implement multiple downcasting in strongly-typed languages. We conclude that multimethods stand out as the single best technique. In the first section, we describe seven commonly used techniques. In the second section, we compare these seven techniques using ten criteria. And, in the third section, we comment on some additional techniques.Multiple downcasting occurs so often that developers use a variety of terms to describe it, and a variety of language constructs and patterns to implement it. "Feed the animals," "driver-vehicle," and "parallel hierarchies" are well-known examples that require multiple downcasting. "Multiple type dispatch" and "covariant subclassing" identify different facets of multiple downcasting. "Dynamic type casting," "typecase statements," and the "visitor pattern" are frequently used to implement multiple downcasting. We believe that multiple downcasting is not a mistake or the result of poor program design, rather multiple downcasting is a specific technique that implements a specific kind of application semantics.In the animal hierarchy shown in Figure 1, cows eat grass, wolves eat meat, and in the superclass, animals eat food. The generalization that animals eat food is imprecise: it ignores the facts that cows only eat grass and wolves only eat meat. So, how should developers write a function to safely "feed the animals" without getting the types mixed up? In Program 1, we show how a developer might like to "feed the animals" in C++. The feed_unsafely function may fail, while the feed_safely function works properly for all combinations of foods and animals. The animal hierarchy will not compile in C++, because the eat method is covariant.In this paper, we elaborate ideas and examples from A Middle-Out Concept of Hierarchy. We adapted the "feed the animals" example from Are Cows Animals? by Shang.
- {1} Craig Chambers (1995) The Cecil Language: Specification and Rationale, http://www.cs.washington.edu/research/projects/cecil/cecil/ www/cecil-home.html, University of Washington.Google Scholar
- {2} Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (1995) Design Patterns, Addison Wesley.Google Scholar
- {3} Bertrand Meyer (1997) Object-Oriented Software Construction, Second Edition, Prentice Hall. Google ScholarDigital Library
- {4} Scott Meyers (1996) More Effective C++, Addison Wesley.Google Scholar
- {5} Hans Muller, John Rose, James Kempf, and Tayloe Stansbury (1989) The Use of Multimethods and Method Combination in a CLOS Based Window Interface, in SIGPLAN Notices, Volume 24, Number 10, Pages 239 to 253, October 1989, ACM Press. Google ScholarDigital Library
- {6} Puppydog P. O. P. and L. B. S. Raccoon (1997) A Middle-Out Concept of Hierarchy, in Software Engineering Notes, Volume 23, Number 3, Pages 111 to 119, May 1998, ACM Press. Google ScholarDigital Library
- {7} David L. Shang (1996) Are Cows Animals?, http://www.sigs.com/publications/docs/oc/9601/oc9601.c.shang.html, in Object Currents, Volume 1, Issue 1, January 1996, SIGS Publications.Google Scholar
- {8} Bjarne Stroustrup (1994) The Design and Evolution of C++, Addison Wesley. Google ScholarDigital Library
- {9} IBM Systems Journal, Volume 35, Number 2, 1996, IBM.Google Scholar
Index Terms
- Multiple downcasting techniques
Recommendations
Type checking modular multiple dispatch with parametric polymorphism and multiple inheritance
OOPSLA '11In previous work, we presented rules for defining overloaded functions that ensure type safety under symmetric multiple dispatch in an object-oriented language with multiple inheritance, and we showed how to check these rules without requiring the ...
Type checking modular multiple dispatch with parametric polymorphism and multiple inheritance
OOPSLA '11: Proceedings of the 2011 ACM international conference on Object oriented programming systems languages and applicationsIn previous work, we presented rules for defining overloaded functions that ensure type safety under symmetric multiple dispatch in an object-oriented language with multiple inheritance, and we showed how to check these rules without requiring the ...
A calcium-influx-dependent plasticity model exhibiting multiple STDP curves
AbstractHebbian plasticity means that if the firing of two neurons is correlated, then their connection is strengthened. Conversely, uncorrelated firing causes a decrease in synaptic strength. Spike-timing-dependent plasticity (STDP) represents one ...
Comments