There's more...
Let's say we do not want a default value in our base class, and want to force that any class that extends the base class to implement a method we would use an interface. In our example, we could throw an error should a base class not be caught. This is fine, but it would be nice if it was caught by the compiler.
Interfaces have many uses, and some will be explored further in later chapters; however, in this case, we will need to ensure that classes that inherit from our base class implement the required methods.
This is one of the many features that interfaces provide. If we declare that a class implements an interface, it will not compile until all methods in the interface are implemented. However, there isn't a way to force ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access