CSharp · Script
using System;
interface Runnable {
void Run(string details);
}
abstract class RunnableBase : Runnable {
public virtual void Run(string more) {
Console.WriteLine(more);
}
}
class Impl1 : RunnableBase {
public override void Run(string extra) {
base.Run(extra);
}
}
class Impl2 : RunnableBase {
public override void Run(string other) {
base.Run(other);
}
}
var random = new Random();
Runnable GetRunnable() {
if (random.Next(2) == 0) {
return new Impl1();
}
else {
return new Impl2();
}
}
var runnable = GetRunnable();
runnable.Run(details: "details");