Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Last active June 19, 2024 22:30
Show Gist options
  • Save dcomartin/613f72b80a3e8fe49cb388ee23a68683 to your computer and use it in GitHub Desktop.
Save dcomartin/613f72b80a3e8fe49cb388ee23a68683 to your computer and use it in GitHub Desktop.
public class Product(int id, OfferingType type)
{
public virtual Option<string> GetDownloadUrl()
{
return Option.None<string>();
}
public virtual Option<string> GetDefaultDownloadFileName()
{
return Option.None<string>();
}
}
public class DownloadProduct(int id, OfferingType type) : Product(id, type)
{
public override Option<string> GetDefaultDownloadFileName()
{
return Option.Some("Some Value");
}
public override Option<string> GetDownloadUrl()
{
return Option.Some("Some Value");
}
}
public class Course(int id, OfferingType type) : Product(id, type)
{
public override Option<string> GetDefaultDownloadFileName()
{
return Option.None<string>();
}
public override Option<string> GetDownloadUrl()
{
return Option.None<string>();
}
}
public sealed class ProductHandler()
{
public void DoStuff(Product product)
{
product.GetDefaultDownloadFileName().MatchSome(
filename =>
{
// Do something with the filename.
});
product.GetDownloadUrl().MatchSome(
url =>
{
// Do something with the url
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment