Sorry, my understanding of role is not enough

Sorry, my understanding of role is not enough.

I add some topic to the following entry.

mop problem 5 - Role and C3 searching is not always necessary

2 Comments

Why, not created a new blog instead of modifing the old?

1) The "diamond problem" is not the reason against multiple inheritance. And you already can say that this one is solved with the C3 MRO (Method Resolution Order) algorithm.

2) Roles don't have to do anything with inheritance. If you inject a Role into a class, you can think of it that the methods will be copied to the new class as if you have written them directly in the class.

3) I still don't see what you exactly want to say with your BUILD/DEMOLISH argument. If you injected a role in your class then in your class you can write a BUILD/DEMOLISH method to instantiate or clean the attributes. It is exactly the same as if you had written your attributes yourself in your class. In fact that is also how you should think of Roles. Instead of Copy & pasting code around you inject a Role.

And BUILD/DEMOLISH is still not part of multiple inheritance. There are constructors and deconstructors that you also have in single-inheritance, or even if you don't use inheritance at all.

4) Okay i said this one. But Single-inheritance is bad. The fact that you can build everything with single-inheritance is not a proof that it is good. You also can build everything without OOP at all, and also everything with a lot of goto Statements.

But we don't consider the last anymore as good, because what is important is not that you can somehow build something with it. It is important how good you can extend, maintain or read something. How good can you reuse code and so on. And Singe-inheritance is bad in all of this.

You also can just use Composition and use delegation to rebuild any single/multiple inheritance. Without getting any problems that both have.

5) I don't really see why providing attributes in roles should make them multiple inheritance. The one has nothing to do with the other. And i don't even see a reason why having attributes you need finalizer.

Leave a comment

About Yuki Kimoto

user-pic I'm Perl Programmer. I LOVE Perl. I want to contribute Perl community and Perl users.