Polymorphism in Programming

Polymorphism in Programming

Kirk Pepperdine emphasizes the importance of polymorphism in object-oriented programming. Polymorphism enables the creation of multiple forms of a class or method, creating localized execution contexts and reducing the need for verbose if-then-else blocks. Instead of reconstructing contexts outside of a given context, polymorphism allows developers to capture context and produce less code that is more readable. For example, in a shopping cart scenario where items may be downloaded or shipped, rather than using an if-then-else block to determine the method of shipment, creating two classes that extend the Item class and implementing the ship method through polymorphism can reduce the number of if-then-else blocks and create a more maintainable codebase. The use of polymorphism, in combination with patterns such as Command and Double Dispatch, can lead to a reduction in if-then-else statements in code, resulting in a smaller and more readable codebase. Missed opportunities for polymorphism can be identified by counting the if-then-else statements in the code. #polymorphisminprogramming




要查看或添加评论,请登录

Harshit Walia的更多文章

社区洞察

其他会员也浏览了