Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
0
Indexable
Never
// Online C# Editor for free
// Write, Edit and Run your C# code using C#  Compiler

using System

public class HelloWorld
{
    public static void Main(string[] args)
    {
        Console.WriteLine ("Hello Mono World");
        Navigator nav1 = new Navigator(new RoadStrategy());
        Navigator nav2 = new Navigator(new WalkingStrategy());
        nav1.buildRoute("A", "B");
    }
}

public interface IRouteStrategy
{
    string buildRoute(string A, string B);
}

public class RoadStrategy : IRouteStrategy
{
    public string buildRoute(string A, string B)
    {
        return "road" + A + B;
    }
}

public class WalkingStrategy : IRouteStrategy
{
    public string buildRoute(string A, string B)
    {
        return "walking " + A + B;
    }
}



public class Navigator
{
    IRouteStrategy routeStrategy;
    
    public Navigator(IRouteStrategy strategy)
    {
        this.routeStrategy = strategy;
    }
    public void buildRoute(string A, string B)
    {
        string route = routeStrategy.buildRoute(A, B);
        Console.WriteLine(route);
    }
}