Till now, we have seen how to use Julia's predefined types as well as user-defined composite types. Now, we are going to delve a little deeper into learning what happens when a user-defined type gets created, and the applications of making this feature more useful to the end user.
As we have already discussed, when we create a new type, we may or may not include field names in the body. Functions, on the other hand, remain distant, and unlike other object-oriented languages, the methods aren't present.
So when we create a new type's object, the default constructor comes into action:
julia> type Family num_members :: Int64 members :: Array{String, 1} end julia> f1 = Family(2, ["husband", "wife"]) Family(2, String["husband", "wife"])
We have declared a composite type, Family
, and it has two fields, num_members
and members
. The first field name is for declaring the number of family members, and the second field name explicitly calls out all family...