Skip to content

Instantly share code, notes, and snippets.

@fjod
Created May 27, 2020 05:37
Show Gist options
  • Save fjod/39ef12b1ae960a50907a01560b2636f1 to your computer and use it in GitHub Desktop.
Save fjod/39ef12b1ae960a50907a01560b2636f1 to your computer and use it in GitHub Desktop.
semi-generic factory example
public abstract class BaseImplementation
{
public abstract void GoToCut(MiniMachine m, Cut cut, bool isScanning);
public abstract void CutMe(MiniMachine m, Cut cut);
public abstract void ScanMe(MiniMachine m, Cut cut);
}
public interface ICuttingImpl
{
BaseImplementation Implement();
}
public interface ICuttingImpl<T> : ICuttingImpl where T : BaseImplementation, new()
{
T Implement<TK>() where TK : T;
}
class CrossCutter : ICuttingImpl<CrossTrapCutting>
{
public CrossTrapCutting Implement<TK>() where TK : CrossTrapCutting
{
return new CrossTrapCutting();
}
public BaseImplementation Implement()
{
return Implement<CrossTrapCutting>();
}
}
class CrossTrapCutting : BaseImplementation
{
//implement abstract class here
}
public static ICuttingImpl GetCutter(Cut _cut)
{
switch (_cut)
{
case TrapCut4Sides _ : return new CrossCutter(); //where TrapCut4Sides : TrapCut
case TrapCut _ : return new TrapCutter(); //TrapCut : Cut
case PerfCutSide _ : return new PerfCutter(); //PerfCutSide : Cut
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment