Different types Quote by Herbert Schildt
““For example, consider a stack (which is a first-in, last-out list). You might have a program that requires three different types of stacks. One stack is used for integer values, one for floating-point values, and one for characters. In this case, the algorithm that implements each stack is the same, even though the data being stored differs. In a non-object-oriented language, you would be required to create three different sets of stack routines, with each set using different names. However, because of polymorphism, in Java you can create one general set of stack routines that works for all three specific situations. This way, once you know how to use one stack, you can use them all. More generally, the concept of polymorphism is often expressed by the phrase “one interface, multiple methods.” This means that it is possible to design a generic interface to a group of related activities. Polymorphism helps reduce complexity by allowing the same interface to be used to specify a general class of action.””
About This Quote
Source Book: Java: The Complete Reference, 1997
Polymorphism lets one interface serve many data types, simplifying code and reducing duplication.
In simple terms: One interface, many uses.
Use polymorphism to write reusable code.
Themes
Mood
Type
When to use this quote
- building libraries
- teaching programming
- refactoring legacy code
Key Concepts
Questions to Reflect On
- When is polymorphism unnecessary?
- How does it affect debugging?
Overuse can hide complexity and cause performance issues.