News for hackers. Stuff that matters.
Re:Inheritance was invented as a performance hack by RHSeeger on Thursday May 08, 2025 @03:57PM (#43930659)
I don't see how that solves the problem. It seems like Video will need to keep it's own copy of CachedMetadaSource, which points back to itself, and go through that access it's metadata in the getMetadata implementation it makes available to it's users. At that point, it might as well just cache the value itself without the extra hoops. The difficult part isn't caching the value, it's preventing every class that implements MetadataSource from having to do so.
Re:Inheritance was invented as a performance hack by svieira on Friday May 09, 2025 @01:43AM (#43934094)
It would be the other way around. You wouldn't pass around the underlying suppliers directly, you'd wrap them. But if you must have state _and_ behavior, then `abstract class` is your friend in Java (while in Scala traits can have fields and constructors, so there is no problem).