I am working on a project for an Arduino-based sytem (i.e. an embedded system) and have a limited amount of ROM for code to live in.
I have found myself needing several different types of collection classes (e.g List, Stack, Queue). After writing these I noticed that aside from the features that make them behave differently (e.g. Add vs Push vs Enqueue, Pop vs Dequeue) they share a lot of common functionality (e.g. they have the exact same fields).
This got me thinking, if I were to create a base class that contained all of the common functionality of the other classes (let's call it Collection) and made the other classes inherit from it, and have them implement only the functionality that differs, would that result in less compiled code?
I'm expecting that it will because the child classes can all refer to the parent's implementations of the common functions, but I could be wrong so I'd rather ask before I attempt this change.
Aucun commentaire:
Enregistrer un commentaire