简体   繁体   中英

what is correct ActionListener structure?

I'm still a student and I'm not sure what is correct structure for an ActionListener ? is it completely ok to just leave them in the layout constructor ? I don't want to train myself bad habits this early on...

to clarify I'm using google's web toolkit which creates action listeners by default in the constructor however prior to that I used ActionListenerHandler (which is sorta a constructor by itself)

I believe the answer is.. it depends.. If it is a one off thing.. you can leave it in the constructor, I assume what you have is anonymous class implementing the ActionListener.

If you want to reuse the ActionListener. You can create a class to implement the ActionListener and simply create instances of that class.

I think some developers don't like creating ActionListeners in the View. Some think it adds logic into a View.

Maybe your View should really expose a method addSomeActionListener(ActionListener actionListener);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM