0

What I want to get clarified is, having a polymorphism factor of 100%, does it means code becomes hard to maintain , and does high polymorphism factor introduce high level of coupling even though inheritance is used to reduce coupling.

The polymorphic factor (PF) is a metric proposed by Abreu & Melo to measure how much a derived type overrides a method from the base class. It's calculated by counting the number of overridden methods compared to the number of methods

0

1 Answer 1

6

It's not a good measure of coupling. Don't even think it's meant to be. Coupling would happen if these overloaded methods called back to their super class but they don't have to.

If they never called back to super and we're at 100% it would mean all the implementation in the super has gone unused, at least for this subtype.

All this really measures is how much implementation comes from the subtype vs the super. Not sure why I'd care about that.

Far more important is those calls back to super. You don't want to make your readers sea sick by sending them up and down the inheritance stack while they read code. This is called the yo yo problem and this stat does not measure it well.

The yo yo problem would be better measured with mouse clicks, or inheritance levels, or even the tears it brings to my eyes.

We tend to favor composition over inheritance today but you can make the same mess with composition. It's just not as likely. Rather then drag readers up and down give them a good place to stand and think about a small part of the problem while hiding as many unneeded details behind well named abstractions as you can.

4
  • does that mean having 100% polymorphism will inrcease the number of unused method overriding and that can increase the complexity of the code hence make the code harder to read but this factor is not a good indicator of coupling ?
    – Char
    Jan 27, 2018 at 1:30
  • 1
    No. Because one subclass may have 100% IF and another may have 1%. Unused code is a problem but this doesn't measure that well either. Jan 27, 2018 at 1:33
  • but does it affect the complexity of the code ?having a high PF?
    – Char
    Jan 27, 2018 at 1:37
  • 1
    Well not really. The superclass may be purely abstract so now we're at 100% IF on every subclass without any unused code or yo yo'ing. The more I think about this the more I think the only thing this has going for it is it's easy to calculate and sounds fancy. Jan 27, 2018 at 1:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.