iDecode
iDecode

Reputation: 29016

Why some method's body does nothing but throw an error?

What's the point of these methods, as they are only throwing UnimplementedError?

You can see in this file, for example

enter image description here

Upvotes: 1

Views: 289

Answers (1)

Mohamed Alsaid
Mohamed Alsaid

Reputation: 960

Updated answer:

The reason for this case can be found in this comment from the class

Platform implementations should extend this class rather than implement it as firebase_core does not consider newly added methods to be breaking changes. Extending this class (using extends) ensures that the subclass will get the default implementation, while platform implementations that implements this interface will be broken by newly added

The class provides default implementations so current sub classes don't break when new methods are added to the base class. If the sub class uses extend and the base class provides a default implementation, then the sub class doesn't have to implement the function to compile.

Note that if the base method does not have a body, then the sub class has to implement it regardless of whether extend or implement were used, which would mean adding new methods is a breaking change for the sub classes.


Old answer:

This is an abstract class that you can find implementations of here and here. I believe the UnimplementedErrors shown in the base class give a meaningful error in case a method was accessed using an object from a class that did not override the function.

So these methods aren't meant to be called as is and should be overridden with appropriate logic as seen in the two links above.

Upvotes: 3

Related Questions