Does the phrase "favor composition over inheritance" apply to Swing components? I'd like to gather some professional opinions about the subject and which code is easier to maintain before I go ahead and design a UI.
Does the phrase "favor composition over inheritance" apply to Swing components?
Yes.
The only time I extend a Swing component is when I need to override one or more of the methods. For instance, I'll extend a JPanel when I want to override the paintComponent method.
All other times, my class will contain the Swing component(s) I need. This allows me to separate my class methods:
frame.getMethod();
from the Swing component class methods:
frame.getFrame().getPreferredSize();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With