Skip to content

dotnet-simformsolutions/strategy-design-pattern

Repository files navigation

Strategy design pattern

  • According to the Gang of Four Definitions, Strategy is a behavioral design pattern that lets you define a family of algorithms, put each of them into a separate class, and make their objects interchangeable.

  • The Strategy Design Pattern is a behavioral design pattern that defines a family of algorithms, encapsulates each one, and makes them interchangeable. It allows the algorithm to vary independently from clients that use it.

Understanding Stratery Design Pattern with an Example in C#:

  • Create an interface with IPaymentStrategy

    image

  • Create PaymentType Enum

    image

  • CreditCardPaymentStrategy Concrete Strategy class implements the IPaymentStrategy Interface and provides implementations for the Pay Method.

    image

  • CashCardPaymentStrategy Concrete Strategy class implements the IPaymentStrategy Interface and provides implementations for the Pay Method.

    image

  • Create PaymentContext class that contains a property that holds the reference of a Strategy object. The client will set this property at run-time according to the payment option the client selected

    image

  • Client code

    image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages