4 ms·
I think thanks to Java opting to use "implements" for interfaces, people no longer associate "inheritance" as the thing we do when we write a fully abstract cla
by slver 5y ago
I think thanks to Java opting to use "implements" for interfaces, people no longer associate "inheritance" as the thing we do when we write a fully abstract class (i.e. interface) and then "inherit" this abstraction to implement it. Interfaces are, of course, crucial.
Not sure I understood your example about the static class vs. function factory tbh though.
- rectang 5y agoBut I don't think a "fully abstract class" is the same thing as an "interface", at least in Java? As far as I know, you can implement multiple "interfaces" but you can still only "extend" one abstract class, even if it is "fully abstract" in that it has no concrete member variables and all methods are abstract.
- slver 5y agoIn Java it isn't but this is specific to Java (and clones of Java like C#). This is because Java has single-inheritance enforcement for classes. C++ for example has multiple inheritance. So the way you do an interface is you just write an abstract class, then extend it to implement it.
- johnmaguire 5y agoIn my experience, whether you use an abstract class or an interface class as your reference depends very much on the problem you are trying to solve - specifically, is there common code shared across all implementations?
- mtinkerhess 5y agoA C++ pure abstract class is equivalent to a Java interface.
- TheCoelacanth 5y agoThat's not inheritance. That's polymorphism. Java doesn't let you have inheritance without polymorphism, but it is possible, see "private inheritance" in C++.
- CuriouslyC 5y agoAs a quick example... class ServiceWrapper: service = ... v1 = ... v2 = ... @static def my_job(): return service.call(v1, v2) vs. def create_service_wrapper(v1=..., v2=..., service=...): def f(): return service.call(v1, v2); return f The class can scale to multiple methods sharing parameters, but the semantics of the factory fall apart if you want to return more than one parameterized function.