Kind of in the same thought around IndieWeb post sub-types (content vs action), I watched this video from Casey Muratori titled “The Big OOPS: Anatomy of a Thirty-five-year Mistake”.
A lot of it is over my head, but he contrasts the idea of class inheritance versus “fat structs.” With Object-Oriented Programming, you might have a base class of common properties and methods and more specialized classes that inherit from that adding their specific properties and methods. With “fat structs,” you would have a single class that has all the properties and methods and a type
property. Different types would only use the properties and methods they need.
A very simple example with C#-ish (untested) code
// Typical inheritance
public class Animal
{
public string Name { get; set; }
public string SayHello()
{
return $"Hello, I'm { Name }!";
}
public Animal(string name)
{
Name = name;
}
}
public class Dog : Animal
{
public string Bark()
{
return "Woof!";
}
}
Compare that to
// "Fat struct"
public class Animal
{
public string Name { get; set; }
public string Type { get; set; }
public string SayHello()
{
return $"Hello, I'm { Name }!";
}
public string Bark()
{
switch (Type)
{
case "Dog"
return "Woof!";
default:
throw new NotImplementedException();
}
}
public Animal(string name)
{
Name = name;
}
}
I can’t get this idea out of my head in the context of IndieWeb post types. There’s so much overlap between many of the post types. Many of the types can exist in two places, a Reply, for example, may be a Note or a Photo. My set up is a base FeedItem
model my various post types, Post
(Article), Note
, Photo
, etc., inherit from. But would it be better if I used a fat Post model? If there was just a single Post
model that had all of the properties for all the types? Perhaps that would be a simpler implementation?