If I'm looking at the code right, none of these methods do anything (aside from the small thing the setModel method does). They call the un-implemented methods in the interface, which have no method bodies. Why would we ever create code like this? The getHeaderText and setHeaderText appear to be traditional getter/setter methods but there's no variable for them to read/write to. Same thing for the setModel method.
I got the solution, but I don't understand what it's doing at all
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
30 September 2021, 14:28
This was one of the tasks that really confused me when I first attempted it too. Check out my post and all the various comments:
my post
0
Gellert Varga
30 September 2021, 14:03
Please send me the specific solution you asked about! I am very curious about it.
(Click on my name: right-click, open in a new tab, and you'll see my page, and there is a "Write a message" button.)
I've solved this task, but I'm pretty sure it's not exactly the way you can download it from CG as the "correct solution". And now, afterwards, I can't download it for myself.
If I can look at this CG code, I might be able to tell you something else about it that might help you understand it - provided I will able to understand this CG-code...
(And I can send you my own solution afterwards, too, which has been accepted.)
+1
Thomas
30 September 2021, 06:28
Consider polymorphism. So try to imagine that there's a class that implements the TableInterface (like TableInterfaceImpl) and you pass an object of that TableInterfaceImpl class to your wrappers constructor.
This is similar to a constructor taking an InputStream and you pass it a FileInputStream.
As you already have seen what a anonymous class is I'll post test code for your main method that implements an anonymous class of the TableInterface and passes a reference of it to your wrappers constructor. Use it as test code.
There are now a lot of patterns like wrapper, adapter and facade that do similar things with slight differences. In theory they implement methods with the same signature and pass data back to the object you passed to the wrappers constructor (the wrapped object) but modified it a little bit. Like here, the getter should uppercase the data before passing the data to the wrapped object. +1