Skip to main content
100%

Gist 0fc0d93c8731fcd68cbfe970c591f3d4

✓ Published0🌍 Public
IIoTeacher
Last edited May 26, 2024
Created on May 26, 2024

This example demonstrates the Strategy design pattern in C# for dynamically selecting shipping cost algorithms in an e-commerce system. It defines an `IEstrategiaEnvio` interface with two concrete implementations, `EnvioExpress` and `EnvioEstandar`, each providing a distinct cost calculation formula based on package weight and distance. The console application prompts the user for these inputs, lets them choose a shipping type, and then calculates the final cost via a `Pedido` class that holds the selected strategy. The code uses standard .NET APIs like `Console.ReadLine` and `double.Parse` for user interaction, with a compiled output shown in a static screenshot.

AI-generated description

Similar vizzes