Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created June 19, 2024 22:20
Show Gist options
  • Save dcomartin/5b91960b708f00d4f8565f3cc4c8a760 to your computer and use it in GitHub Desktop.
Save dcomartin/5b91960b708f00d4f8565f3cc4c8a760 to your computer and use it in GitHub Desktop.
public abstract class Product(int id)
{
public int Id { get; } = id;
}
public class Template(int id) : Product(id) { }
public class Ebook(int id) : Product(id) { }
public class OfflineCourse(int id) : Product(id) { }
public sealed class ProductHandler(ResourcesHelper resourcesHelper)
{
public void DoStuff(Product product)
{
if (product is Template ||
product is Ebook||
product is OfflineCourse)
{
var fileName = resourcesHelper.GetDefaultDownloadFileName(product);
var downloadUrl = resourcesHelper.GetDownloadUrl(product);
}
}
}
public sealed class ResourcesHelper
{
public string? GetDownloadUrl(Product product)
{
if (product is Template ||
product is Ebook||
product is OfflineCourse)
{
// some code to do this...
return "TODO: get the download URL";
}
return null;
}
public string? GetDefaultDownloadFileName(Product product)
{
if (product is Template ||
product is Ebook||
product is OfflineCourse)
{
// some code to do this...
return "TODO: get the file name";
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment