Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a multiple inheritance helper #5

Open
trusktr opened this issue Oct 7, 2018 · 1 comment
Open

Add a multiple inheritance helper #5

trusktr opened this issue Oct 7, 2018 · 1 comment

Comments

@trusktr
Copy link
Owner

trusktr commented Oct 7, 2018

gizmo is the first and only other library that mentions making making trees of prototypes with Proxy to do multiple inheritance. I had this idea when I was trying to make my multiple() helper. It'd be interesting to add the feature here in lowclass

@rdking
Copy link

rdking commented Sep 25, 2020

Let me throw another idea at you. Why bother making a tree at all? Consider something. When you're using multiple inheritance, what you want to inherit is exactly the list of classes in your base, right? Why not treat each class exactly as classes were intended to be, a black box, and not worry at all for their ancestry? If you don't get what I mean, let's look at how this works for the diamond problem:

class A {}
class B extends A {}
class C extends A {}
class D extends [B,C] {} //Fictitious notation

The question here is whether or not D should care that both B & C extend A. If we treat both B and C as non-extended base classes, then D has no issues. An instance of B would simply be initialized by A and contain A's components. The same is true for C. So now the only problem is in how you reference the public members of B & C which have the same name. This is the same problem you'd face even if B & C did not extend the same class. This leaves you with only that 1 problem to solve. In the end, you'd still have an inheritance tree, but the tree would be self-managing. Furthermore, you wouldn't have to worry with accidental breaks caused by competition between expectations of B and C over their own copy of A's state.

If you look at the README.md for ClassicJS, you'll see that I included an extra feature in this.super() after it's use as the super() replacement. It takes an optional argument letting you specify a base class to access. Once I've written enough tests to trust the current state of ClassicJS, then I'll add multiple inheritance. That'll really put the this.super(<fn || fn.name>) feature to use since you'll be able to target a particular base class as needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants