Methods in Julia
Julia supports methods defined on struct types.
To run the program:
In Julia, methods are defined outside of the struct definition, unlike some object-oriented languages. The first argument of a method is conventionally named self
or the first letter of the type name (like r
for Rect
), and it determines which type the method is associated with.
Julia uses multiple dispatch, which means that methods are chosen based on the types of all their arguments, not just the first. This is more flexible than single dispatch used in many object-oriented languages.
In Julia, there’s no distinction between value and reference types in method calls. The language handles this automatically, and the syntax is the same whether you’re working with values or references.
Next, we’ll look at Julia’s mechanism for grouping and naming related sets of methods: abstract types and interfaces.