[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

NazemMahmud/strategy-pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Strategy pattern

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.

Here, an example is used as a TDD (Test Driven Development) approach.

Only test file is called from here.

Problem Domain

  • There are some products with code, name & price. See src/Modal/Products file

  • There are some offers for specific product, such as

    • Buy 1 get 1 offer for Mango
    • Bulk discount offer for Strawberry: buy item >=3, price will be reduced to a specific amount, in this example, 4.5

    See src/Modal/Offers file

  • Now, calculate total price when checking out

Run Test

To run test file through CLI using phpunit, try like this:

./vendor/bin/phpunit tests/CheckoutTest.php

About

A practical example of strategy pattern

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages