Skip to content

Instantly share code, notes, and snippets.

Created December 7, 2016 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/0559fc91dce0e9702733b40f8dd2702c to your computer and use it in GitHub Desktop.
Save anonymous/0559fc91dce0e9702733b40f8dd2702c to your computer and use it in GitHub Desktop.
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