BP111: Use commands instead of events

Command pattern allows requests to be encapsulated as objects where the request logic can be easily executed from outside of the object.

You give a caller a standardized way how to execute the command. The caller doesn't need to know anything about the commnd logic in order to be able to execute it.

Because the command has predefined interface, replacing one command by different command is easy, you just change a reference to the command.

Command are less coupled than events. They allow for better modularization and code maintenance because thay can be stored in standalone classes.

But if you want to use them in a similar way as you use events so that all the logic would be encapsulated in your ViewModel class, nothing is preventing you from doing so - you will just use commands with lambdas.

Using a command you can define a logical block that is to be executed in XAML while the logic itself is implemented in the command. 

Comments

No Comments Yet.
Be the first to tell us what you think.

Download Better Coder application to your phone and get unlimited access to the collection of enterprise best practices.

Get it on Google Play