3

I need to create subclass of the Patch object's class in MATLAB 2014b but MATLAB does not allow me to do so:

Class 'matlab.graphics.primitive.Patch' is Sealed and may not be used as a superclass.

Is there a hack around this?

Sia
  • 919
  • 1
  • 8
  • 18

2 Answers2

1

No - you can't subclass a class that is Sealed, and matlab.graphics.primitive.Patch is a built-in class, so you can't make a (hack) edit to unseal it.

The best you can do is to use an Adapter pattern - create your own class, storing a Patch as a private (and maybe hidden) property, and then wrap all its properties and ones of your own, implementing set and get methods that pass through the value to/from the underlying Patch. Do something similar for any methods of Patch that you need. You may also need to listen to property change events on the Patch and respond to them appropriately.

Then you can add your own methods as well, and/or modify the existing method and property behavior as required.

Sam Roberts
  • 23,951
  • 1
  • 40
  • 64
  • Yeah, those ideas are some of the things I thought about at first. But I was wondering if there would be a (neat,) undocumented way to circumvent this limitation (e.g. via accessing the underlying `java` objects, etc). I have actually implemented what you have suggested actually, but like I said I was wondering whether there's a more general way to achieve the same result. – Sia Mar 20 '15 at 21:05
  • Unfortunately no, not that I'm aware of. – Sam Roberts Mar 20 '15 at 21:51
0

No. If the class is sealed, it shall not be derived from. There are probably good reasons why it has been chosen to be sealed; other classes may assume a particular implementation which you can override if you were to inherit from the class.

Rollen
  • 1,212
  • 11
  • 15