Lets say I have the following types:
type cat
cry:: String
legs:: Int
fur:: String
end
type car
noise::String
wheels::Int
speed::Int
end
Lion = cat("meow", 4, "fuzzy")
vw = car("honk", 4, 45)
And I want to add a method describe
to both of them which prints the data inside them. Is it best to use methods to do it this way:
describe(a::cat) = println("Type: Cat"), println("Cry:", a.cry, " Legs:",a.legs, " fur:", a.fur);
describe(a::car) = println("Type: Car"), println("Noise:", a.noise, " Wheels:", a.wheels, " Speed:", a.speed)
describe(Lion)
describe(vw)
Output:
Type: Cat
Cry:meow Legs:4 fur:fuzzy
Type: Car
Noise:honk Wheels:4 Speed:45
Or should I use a function like in this question I posted before: Julia: What is the best way to set up a OOP model for a library
Which method is more efficient?
Most Methods
examples in the documentation are simple functions, if I wanted a more complex Method
with loops or if statements are they possible?