Are there any general-purpose programming languages with classes, objects, methods, interfaces, and so on, which disallow class-based inheritance?
This reads very much like a description of VBA - Visual Basic for Applications, embedded in Microsoft Office and other VBA-enabled hosts (e.g. AutoCAD, Sage 300 ERP, etc.), or even VB6. The "A" of "Basic" stands for "All-purpose" anyway, so there's the "general-purpose" part.
VB6/VBA has classes (and therefore objects), methods and interfaces - you could define an ISomething
interface in a class module like this:
Option Explicit
Public Sub DoSomething()
End Sub
And then have another class that does this:
Option Explicit
Implements ISomething
Private Sub ISomething_DoSomething()
'implementation here
End Sub
Such a class, exposing no public members, could only ever be accessed via its ISomething
interface - and there could very well be dozens of different implementations of ISomething
out there, so OOP VBA code is perfectly capable of polymorphism, and it's perfectly legal for a given class to implement multiple interfaces, too.
VB6/VBA does not allow class inheritance however, so you can't inherit an implementation from another type, only its interface. Now, whether this is an accident, a design flaw, a stroke of genius or a huge ugly oversight is open for debate; it's not clear whether VB6/VBA takes this to heart, but it most definitely enforces it.
If Go doesn't do class inheritance and is nonetheless an OOP language, then I don't see why VB6/VBA couldn't be considered an OOP language as well. </PreemptiveResponseToVBAHatersThatWillSayItIsNotAnOOPLanguage>
prototype
is also useful for when you have public methods and properties that should be shared between instances. It's also useful because it allows you to properly use theinstanceof
operator in JavaScript:if (foo instanceof Foo) { ...
. – Greg Burghardt Oct 06 '14 at 18:27implements
keyword and interfaces (as opposed to the inheritance of state and behaviour introduced with the use of theextends
keyword on classes containing any implementation). – toniedzwiedz Oct 06 '14 at 18:29new
,this
andprototype
are all too much of a minefield for common use IMO. – Benjamin Hodgson Oct 06 '14 at 21:02exec
... I'm not saying inheritance should be abandoned altogether, I just want to know if anyone's tried to make it work and what it would look like. – Benjamin Hodgson Oct 06 '14 at 21:43