0

I have to resolve this task for my college... I need to create one new class (with one new method, just to show I know how to do it) which extends swt class which is final (so it can't be extended in a classic way with extend keyword..). I have been told I can write wrapper class and instantiate final class object inside it. But what then?

I would be really thankful if someone can show me some example of this kind of extending (with some final class, new class and using method of new class which extends final class), because I have no idea how to do it.

greg-449
  • 109,219
  • 232
  • 102
  • 145
Ivan
  • 3
  • 1
  • Does this class have an interface? – Mureinik Feb 01 '14 at 14:43
  • Mureinik - Class doesn't have an interface... Greg - GridLayout class – Ivan Feb 01 '14 at 15:01
  • For `GridLayout` this sounds like it is probably the wrong way to do whatever it is you want. – greg-449 Feb 01 '14 at 15:20
  • The task you're given should not be a task at all. You DON'T need to know how to extend a final class - and thus mess with the given framework. If the class is final and shouldn't be, due to new requirements or bad architecture, then it should be fixed, instead of trying to override it. This task is ridiculous! – Martin Asenov Feb 01 '14 at 15:22

1 Answers1

1

Use the decorator pattern to wrap the object and extend it.

To add more to this answer:

The GridLayout extends Layout. So create a wrapper around the GridLayout extending Layout and add your extension to the wrapper. If you want to change the way, the layout is performed you add your code to the layout method.

Hannes
  • 2,018
  • 25
  • 32