You are on page 1of 1

using System;

namespace ChikenEgg
{
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World");
}
}
public interface IBird
{
Egg Lay();
}
public class Egg
{
private readonly Func<IBird> _createBird;
private bool _hatched;
public Egg(Func<IBird> createBird)
{
_createBird=createBird;
}
public IBird Hatch()
{
if(_hatched) throw new InvalidOperationException("Egg already Htched");
_hatched=true;
return _createBird();

}
}

public class Chicken:IBird


{
public Egg Lay()
{
var egg=new Egg(()=>new Chicken());
return egg;
}
}

You might also like