Created
December 7, 2016 17:44
-
-
Save anonymous/0559fc91dce0e9702733b40f8dd2702c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace RobotConsole | |
{ | |
/* | |
* In a real implementation I probably would use MEF as the base framework for parts | |
* | |
*/ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
IChip sum = new Sum(); | |
IRobot luz = new Robot(sum); | |
var total = (int) luz.Execute(new int[] {1, 2, 3 }); | |
Console.WriteLine($"sum={total}"); | |
IChip sort = new Sort(Sort.SortOrderEnum.Ascendeing); | |
luz.Install(sort); | |
var sorted = luz.Execute(new int[] { 1, 10, 2, 9, 3, 8, 4, 7, 5, 6 }); | |
Console.WriteLine($"Total Number of Installs={luz.ChipInstallCount}"); | |
Console.ReadKey(); | |
} | |
} | |
public interface IChip | |
{ | |
object Execute(int[] source); | |
} | |
public interface IRobot | |
{ | |
void Install(IChip chip); | |
int ChipInstallCount { get; } | |
object Execute(int[] source); | |
} | |
public class Robot : IRobot | |
{ | |
private int installCount = 0; | |
private IChip Chip; | |
public int ChipInstallCount | |
{ | |
get { return installCount; } | |
private set { } | |
} | |
public String Name | |
{ | |
get { return "LUZ"; } | |
private set { } | |
} | |
public void Install(IChip chip) | |
{ | |
this.Chip = chip; | |
installCount++; | |
} | |
public Robot(IChip chip) | |
{ | |
this.Chip = chip; | |
} | |
object IRobot.Execute(int[] source) | |
{ | |
return this.Chip.Execute(source); | |
} | |
} | |
public class Sort : IChip | |
{ | |
public enum SortOrderEnum | |
{ | |
Ascendeing = 0, | |
Descending | |
} | |
private SortOrderEnum SortOrder = 0; | |
public Sort(SortOrderEnum sortOrder) | |
{ | |
this.SortOrder = sortOrder; | |
} | |
public object Execute(int[] source) | |
{ | |
return source.OrderBy(i => i); | |
} | |
} | |
public class Sum : IChip | |
{ | |
public object Execute(int[] source) | |
{ | |
return source.Sum(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment