The strategy design pattern (behavioral design pattern) allows you to change the behavior
of an application that does not violate the open/closed principle (OCP)
By defining a family of algorithms, encapsulate each one, and make them
interchangeable, it makes the algorithm vary independently
from the application that use it.
Example: Build a soccer game that allow a user play with a computer
Steps:
1. Create an IComputerPlayer interface
2. Create 3 classes: EasyComputerPlayer, MediumComputerPlayer and HardComputerPlayer that implement the IComputerPlayer interface
3. Create a SoccerGame class that allow user to play soccer with one of 3 ComputerPlayer level above
4. Create a demo program that uses the SoccerGame class
Auf dieser Seite können Sie das Online-Video Using Strategy Pattern in Java mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Improve Your Programming skills 09 September 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 47 Mal angesehen und es wurde von 5 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!