Created
October 18, 2020 20:50
-
-
Save MichalBrylka/861b211df367f13c26c033adeca435ff 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; | |
| namespace DotnetCommunityDemoNet5 | |
| { | |
| abstract class Component:ICloneable | |
| { | |
| public int ComponentId { get; } | |
| protected Component(int componentId) => ComponentId = componentId; | |
| public abstract object Clone(); | |
| } | |
| class Calculator : Component | |
| { | |
| public float Factor{ get; } | |
| public Calculator(int componentId, float factor) : base(componentId) => Factor = factor; | |
| //type known on call site!!! | |
| public override Calculator Clone() => new Calculator(ComponentId, Factor); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment