Showing posts with label interfaces. Show all posts
Showing posts with label interfaces. Show all posts

11 Sept 2012

Interfaces, nested classes and inheritance

In one of my previous posts I said that interfaces in CoffeeScript can be written as usual classes and extended by other classes (if only you want to write Java-style interface, of course). I was wrong.
There are two main problems with Java-style interfaces in CoffeeScript:
  1. Every class in Java can have only one parent but implement as many interfaces as you like. CoffeeScript classes can extend only one class. That's it. If CoffeeScript allowed multiple inheritance everything would be as easy as I said before. However, it doesn't.
  2. Every class in Java is instance of all the interfaces it implements. In CoffeeScript instanceof operator return true only for classes in objects' prototype chain. No exclusions, no possibility to override.
So, I've tried to solve both of this problems.