Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Event Handling: What is the best way?

 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,

I am creating a software which has a JMenu. In one of its submenus, there are 20 JMenuItems which will be doing the exact same work, passing an "File" as a parameter to another method. The only difference is, these 20 menu items pass 20 files. So, this is my question;

Do I need to create 20 sub classes for Event Handling? Or, isn't it easy and OK to just use one sub class as an Event handler, and use If else statements to identify the caller?
I am asking this because I feel creating 20 sub classes for doing exact same work which has a small difference is time consuming. Please help..
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Subclass once. Pass the "file" in the constructor. Refer to this variable while executing the action.
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Subclass once. Pass the "file" in the constructor. Refer to this variable while executing the action.


wow! That was awesome! Thanks a lot!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic