vendredi 5 novembre 2021

Strategy design pattern for mouse events Javascript

I want to implement the Strategy Design pattern in Javascript where clicking a button would change the 'Tool' currently being used; which calls different functions based on the currently selected tool. Or in other words dynamically change which function will be called when an event happens such as a mouse click.

I'm wondering what would be the best way to do this? Or a different design pattern that I haven't considered?

I know I could explicitly define a class to do this. But because Javascript doesn't natively support interfaces, I'm assuming there's a better way.

Aucun commentaire:

Enregistrer un commentaire