Skip to content

Instantly share code, notes, and snippets.

@MichalBrylka
Created October 18, 2020 20:50
Show Gist options
  • Select an option

  • Save MichalBrylka/861b211df367f13c26c033adeca435ff to your computer and use it in GitHub Desktop.

Select an option

Save MichalBrylka/861b211df367f13c26c033adeca435ff to your computer and use it in GitHub Desktop.
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