I am working on a slide-based application in C++. Each slide has a slide-items collection which can include items like caption, button, rectangle, etc.
Only some of these items support fill, while others don't.
What is the best way to implement the fill for the slide items in this case? Here are two ways that I thought of:
Create an interface
Fillable
and implement this interface for slide items which support fill, keeping all the properties related to fill in the interface. When iterating over the list of slide items, dynamic_cast them intoFillable
, and if successful, do the operation related to fill.Make a
fill
class. Make afill
pointer a part of slide item class, assign thefill
object to thefill
pointer for those objects which support fill, and for rest of them keep it null. Give a functionGetFill
, which will return thefill
for the items if it exists otherwise returnsNULL
.
What's the best approach for this? I'm interested in performance and maintainability.