I have a class called Image and a class that extends it called ImageSheet.
ImageSheet is the same as Image except it has additional fields such as the number of frames on the sheet of images.
What I want to do is have it so I can call drawImage(img, frame) and have img be either a Image or an ImageSheet and handle them with the same method with the only difference being that if it’s an Image then the frame field is ignored but when it’s an ImageSheet the frame field is read and used to draw the specific frame.
I’m trying to avoid having separate methods for if it’s an Image or an ImageSheet because I already have 3 different drawImage() methods that accept different input variables and if I did one for each class I’d have 3 pairs of methods where each pair is essentially exactly the same.
How can I pull off what I have in mind?
I assume that drawImage is a method outside Image/ImageSheet and if you are avoiding a separate method, you may use instanceof and check if the img parameter is an instance of imageSheet.