Object-Oriented Design and Data Structures
We now discuss the third of these, inheritance. Inheritance is a mechanism that supports extensibility and reuse of code, both across programs and within programs. Suppose someone gives us an implementation of the Board interface that we saw in the previous lecture. In the ABoard implementation, the game state is represented by a 2D array of integers: Now suppose that we want to build a better game implementation by reusing this code. For example, we might want the game to log all of the moves that have been made. We could proceed by copying the code of ABoard to create a new class LogBoard, which we could then add new fields and methods to. But this strategy doesn't work very well when the original supplier of ABoard fixes some bugs and gives us a new version ABoard'. Now we have to either apply the same bug fixes to LogBoard on the code that we copied from ABoard to get a new LogBoard', or start afresh from ABoard' and build a new LogBoard' from it. Either way, it will be a lot of wo
Inheritance and the specialization interface Recall that we identified three key elements of OO programming: Encapsulation Subtyping Inheritance We now discuss the third of these, inheritance. Inheritance is a mechanism that supports extensibility and reuse of code, both across programs and within programs. Motivating example Suppose someone gives us an implementation of the Board interface that we saw previously. In the CBoard implementation, the game state is represented by a 2D array of integers: class CBoard implements Board { private int[][] tiles; public int tile(int r, int…
related reading
- Favoring Composition Over Inheritance In Java With Examples - GeeksforGeeksgeeksforgeeks.org
- LEAP 71 | PicoGK.org Blogpicogk.org
- Information hidingen.wikipedia.org
- 14. Polymorphism - CS2030S Programming Methodology IInus-cs2030s.github.io
- how I think when I think about programming - alice mazalicemaz.com
- Inheritance · Crafting Interpreterscraftinginterpreters.com
- Object-oriented programming - Learn web development | MDNdeveloper.mozilla.org
- artima - Josh Bloch on Designartima.com
- 9. Classes — Python 3.14.6 documentationdocs.python.org
- class - Why do Python classes inherit object? - Stack Overflowstackoverflow.com
- Object-Oriented Programming (OOP) in Python – Real Pythonrealpython.com
- Lab 1: Simulation I - CS2030S Programming Methodology IInus-cs2030s.github.io