Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understand Command Pattern in Swing

I can see how Swing uses Decorator and Observer pattern.

Observer: Every component(eg. JButton) is a subject which can add observers(ActionListeners). When someone pushes a button it notifies all its ActionListeners by calling their actionPerformed(ActionEvent e).

But how about Command Pattern?

When I am making classes that implements ActionListener (eg: MyActionListener) the actionPerformed(ActionEvent e) is now the execute command?

It confuses me that actionPerformed(ActionEvent e) is used both as a execute() and a update() method. Am I right here?

like image 886
Mads Andersen Avatar asked Jan 23 '23 13:01

Mads Andersen


1 Answers

Here is an article that will help. Basically, it is saying you can create concrete command classes that interact with a target object by deriving the ActionListener. Then you can expand what an action event invoker will do by registering these decoupled commands to it.

like image 138
Chap Avatar answered Jan 28 '23 15:01

Chap