DEV Community

Discussion on: The Command Design Pattern in JavaScript

Collapse
 
crimsonalucard profile image
Brian

You completely over-thunk the command pattern. It's one of those patterns that's classified as obsolete. It's largely useless in javascript and was mostly designed for JAVA.

The reason is the command pattern was designed for the older version of JAVAs lack of ability to accept a function as a first class parameter.

So to get around this they created the command pattern. The key here is JAVA methods cannot accept a function as a parameter but it can accept another class as a parameter.

Essentially just package the function you want to pass along into an class as a method and pass the class itself! This is a workaround for the lack of the existence of a anonymous function in older versions of JAVA.

That's literally all the command pattern is.

Collapse
 
rolandcsibrei profile image
Roland Csibrei

Actually, the only reason I have implemented this pattern several times is the undo functionality.

Collapse
 
kamalhm profile image
Kamal

What's the top 3 design pattern to use in Java now that Java can pass function as a parameter?