Why is the fields pragma incompatible with multiple inheritance in Perl? -


Multiple inheritance is great, and as long as your legacy is a clear understanding of inheritance and some potential disadvantages (as described in them) again It does not even discuss the prohibition of using Prague with many heritage; Actually, I can not find any document about it ...

Here's an example:

  Package Parents; Use the field 'Field 1'; Package Parent2; Use field 'field2'; Package child; Use base qw (parent 1 parent 2);  

It fails with error: "Heirs can not grow in the area ..."

This does not work even when both parents There are areas similar to that. Even when they are definitely the same, because they come from a common grandparent:

  package grandfather; Use the field QW (Field 1); Package parent 1; Use base 'grandfather'; Package Parent2; Use base 'grandfather'; Package child; Use base qw (parent 1 parent 2);  

It is a disturbance to implement it correctly that the index of the field of an object is always the same as the index of its origin. I'm not sure that this requirement is really necessary, though ... unlike C ++, where an object can be accessed by using a pointer typed, Pearl always knows the real type of an object When it works on its reference (actually field pseudo-core is basically a vtable, placed on every single object instance). And especially in the second example above, each inherited field comes from the inherited field both parents, so they can be combined together and there is no contradictory indicator.

I'm sure

Can anyone comment on this with some internal knowledge of Pearl?

1) You can try to use the delegation instead of heritage.

2) Also, some documents (including the above link) due to problems with multiple heritage are due to prism. Pearl 5.10 has changed the implementation of the "Fields" program to something other than pseudo-weapons - If this is an option, use the approach that you use in Perl 5.10 and it can only work (I do not have access to 5.10, so can not be used, sorry)

PS "me No document can be found about this ... "-" official "documents mention at least one mention of the camel book (" Programming Pearl ", Pearl series of O'Reilly), third edition, chapter 31.3. "Use Base":

"Multiple succession of field classes are not supported. The basic program raises an exception if there are more than one field named base class."


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -