Inheritance and Variance

If we had to choose the most important thing to learn in Julia, or in any programming language, then it has to be the concept of the data type. Abstract types and concrete types work together, providing the programmer with a powerful tool to model solutions to solve real-world problems. Multiple dispatch rely on well-defined data types to invoke the right functions. Parametric types are used so that we can reuse the basic structure of an object with a specific physical representation of the underlying data. As you can see, having a well-thought-out design for data types is of the utmost importance in software engineering practice.

In Chapter 2, Modules, Packages, and Data Type Concepts, we learned about the basics of abstract and concrete types and how to build a type hierarchy based upon an inheritance relationship between the types. In Chapter 3Designing Functions and Interfaces, and Chapter 5, Reusability Patterns, we also touched on the subject of parametric types and parametric methods. In order to utilize these concepts and language features effectively, we need a good understanding of how subtyping works. It may sound similar to inheritance, but it is fundamentally different.

In this chapter, we will go deeper and explore the meaning of subtyping and related topics, which includes the following topics:

  • Implementation inheritance and behavior subtyping
  • Covariance, contravariance, and invariance
  • Parametric methods and diagonal rule

By the end of this chapter, you will have a good understanding of subtyping in Julia. You will be more equipped to design your own data type hierarchy and utilize multiple dispatch more effectively.

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

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