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? I’d like to
Share
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:
from the Swing component class methods: