I'm stuck on this for hours. I should make UML class diagram for Swing application in a college project. I envisioned one main screen from which I can open one of several screens depending on chosen option. All of those screens have several identical components (like application logo, log out button etc).
Now, I've read it's not recommended to inherit JFrame so I avoided putting those in a class that inherits JFrame that is again inherited by those other classes but somehow it also does not seem okay to not have inheritance and instead list those components as attributes in every class.
So, what IS the right way to do it?
Any different screen are usually considered as a class. The screen with concrete data in it is an instance of the class.
Any sort of subelement of the screen is obviously, another class. Again, its exemplar with date is an instance.
A screen class has subelements of different classes. They really ARE attributes, and changing the natural logic would be very unhappy idea.
If screens have same elements and differ only in their content, and this fact is conceptual, if they MUST be the same, those screens belong to the same class. If they are so similar only accidentally, and further development can change it, they should belong to different classes.
Inheritance could be conveniently used, too. If you have yellow buttons and yellow buttons with dots, the latter could be descendants of the former. Here the Liskov principle won't be broken. Don't forget, the base principles are set in SOLID, there is NOT such principle as don't use inheritance, and you needn't use composition out of pure fashion.