Welcome to the fifth part of my series on essential programming best practices for technical writers. In the last post, I discussed the concept of reusability. On this post I’ll focus on the principle of polymorphism.
Polymorphism allows objects from different classes to be treated as instances of a common superclass, enabling them to respond to the same method or operation in unique ways based on their class type. This promotes code flexibility, extendability, and enhances maintainability and scalability by eliminating the need to modify the original codebase.
There are two primary types of polymorphism:
| Type of Polymorphism | Description |
|---|---|
| Compile-time Polymorphism (Static Polymorphism) | Occurs when a class has multiple methods with the same name but different parameters (by number, type, or both). Known as method overloading or operator overloading, the method to execute is determined at compile time based on the method signature. |
| Runtime Polymorphism (Dynamic Polymorphism) | Happens when a subclass overrides a method from its superclass with the same name and parameters. At runtime, the actual type of the object determines which method is executed, allowing subclasses to offer specialized behavior while maintaining a consistent interface. |
Example: In a graphics application, you might have a superclass called Shape and subclasses like Circle, Rectangle, and Triangle. Although each shape calculates its area differently, polymorphism lets you call the calculateArea() method on any shape object without needing to know its specific type.
When creating user guides or tutorials, knowledge of polymorphism allows writers to explain how developers can extend functionality, customize behavior, or interact with objects in a scalable way. It also helps them teach best practices for reusing and extending code.
These are the basics of polymorphism. In the next post, we’ll explore the topic of modularity.
2 thoughts on “Programming Best Practices for Technical Writers – Polymorphism”