Created
May 27, 2020 05:37
-
-
Save fjod/39ef12b1ae960a50907a01560b2636f1 to your computer and use it in GitHub Desktop.
semi-generic factory example
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
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