0

I have a parent class MediaWindow which is extended by multiple child classes VideoWindow, PictureWindow etc.

Each subclass of classes must implement two particular functions which relate to resizing.

My thought was for the parent class to implement an interface e.g. IResizableWindow.

Since every MediaWindow must provide an implementation of the resizing function I thought it makes sense that MediaWindow implements IResizableWindow directly. However since the subclasses each need to have different implementations of the resizing functions, the functions cannot be directly implemented on the parent class.

public interface IResizableWindow {
   function resizeContent():void;
   function getResizeDimensions():Rectangle;
}
public class MediaWindow implements IResizableWindow {
    ...
}

public class ImageWindow extends MediaWindow {
   ...
   public function resizeContent():void {
      // function implementation
   }
   public function getResizeDimensions():Rectangle {
      // function implementation
   }
   ...
}

However this will throw the error Interface method resizeContent in namespace IResizableWindow not implemented by class MediaWindow. & same for the getResizeDimensions() function.

Is the best solution for each of the subclasses to individually implement the IResizableWindow interface?

e.g.

public class ImageWindow extends MediaWindow implements IResizableWindow {
    ...
}

It feels annoying to have to explicitly state that every single child class implements the interface individually when I want it to be the case for all subclasses of MediaWindow but perhaps this is the only way.

Thanks for your advice in advance.

2
  • Yes in short. Or call class MediaWindow "abstract", these must not be initialized but instances of subclasses could exist, be created but those subclasses must implement all the interface methods. (But IIRC there's no abstract class in AS3, outatime to verify) Commented Dec 13, 2023 at 15:18
  • @Vesper that makes sense. I may just scrap the idea of using an interface and create some "abstract" methods on the MediaWindow which throw an error if not overridden. I'd rather a neater way of doing it but seeing as I don't want every subclass to have to individually implement the interface it'll have to do. Commented Dec 13, 2023 at 16:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.