0% found this document useful (0 votes)
20 views2 pages

Understanding the Strategy Pattern

The Strategy Pattern defines a family of interchangeable functionalities, encapsulating each behavior within its own class to avoid subclassing and conditional statements. This pattern facilitates easier extension and incorporation of new behaviors. It is particularly useful when multiple classes differ only in their behaviors or when different variations of an algorithm are needed.

Uploaded by

Suresh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

Understanding the Strategy Pattern

The Strategy Pattern defines a family of interchangeable functionalities, encapsulating each behavior within its own class to avoid subclassing and conditional statements. This pattern facilitates easier extension and incorporation of new behaviors. It is particularly useful when multiple classes differ only in their behaviors or when different variations of an algorithm are needed.

Uploaded by

Suresh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Strategy Pattern

A Strategy Pattern says that "defines a family of functionality, encapsulate


each one, and make them interchangeable".

The Strategy Pattern is also known as Policy.

Benefits:

o It provides a substitute to subclassing.


o It defines each behavior within its own class, eliminating the need
for conditional statements.
o It makes it easier to extend and incorporate new behavior without
changing the application.

Usage:

o When the multiple classes differ only in their behaviors.e.g. Servlet


API.
o It is used when you need different variations of an algorithm.

Strategy Pattern in (Core Java API's) or JSE 7 API's:

Strategy Pattern in (Advance Java API's) or JEE 7 API's:


UML for Strategy Pattern:

You might also like