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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With