XF 2.2 Can you extend abstract classes?

Jaxel

Well-known member
I would like to extend the ThreadType abstract class. Specifically, I want to extend the pinned first post class... And I want to extend this class for ALL thread types.

However, I can't seem to extend the abstract class. Instead, I am forced to extend each type individually. This would cause a lot of redundancy, and not work with third party add-ons that create their own new thread types.

Is there a better solution for this?
 

Sim

Well-known member
I would like to extend the ThreadType abstract class. Specifically, I want to extend the pinned first post class... And I want to extend this class for ALL thread types.

However, I can't seem to extend the abstract class. Instead, I am forced to extend each type individually. This would cause a lot of redundancy, and not work with third party add-ons that create their own new thread types.

Is there a better solution for this?

No - you can't extend an abstract class, you'll need to do class extensions for each of the concrete classes (I've come across this myself previously).

As @JulianD suggested, a trait might help keep things DRY.

Expecting it to work with 3rd party addons is always going to be fraught - but don't forget that you can create class extensions for a 3rd party class from someone else's addon - it won't break if the addon isn't installed. Of course, you can only create extensions for classes you know about - so this is not a universal solution.
 
Top