Chapter 12

How does implementation inheritance differ from behavior subtyping?

Implementation inheritance allows a subclass to inherit both fields and methods from a super-class. Behavior subtyping allows a subtype to inherit methods defined for a super-type.  

What are some major issues associated with implementation inheritance?

Implementation inheritance is problematic because sometimes, the subclass may not want to inherit the fields from a super-class even when it makes logical sense to define the parent-child relationship. As demonstrated from the square-rectangle problem, a subclass may be more restrictive and take away features rather than adding new functionality on top of the super-class. Second, implementation inheritance suffers from the fragile base class issue, for which changes to the super-class may unintentionally modify the behavior of the subclass.

What is duck typing?

Duck typing is a dynamic feature that allows a method to be dispatched without strong type checking. A function may be dispatched as long as it adheres to the expected interface contract.

What is the variance of method arguments and why?

Method arguments are covariant as they are consistent with the Liskov Substitution Principle, which states that a function that is defined to accept type S should be able to work with any subtype of S.

Why are parametric types invariant in Julia?

Parametric types are invariant in Julia for a very practical reason. The type parameter unambiguously determines the memory layout of the underlying container. When it is invariant, there is an opportunity to achieve high performance by compacting storage data consecutively without having to dereference pointers.

When does the diagonal rule apply?

The diagonal rule is applied whenever a type variable occurs more than once in a covariance position. There is an exception to the rule when the same type variable is unambiguously determined from an invariant position such as in a parametric type.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset