Hello all,
I must say that I`m quite new to object oriented programming.
Do I understand correctly from the manual that in Julia (unlike python) you
do not use the keyword "self" and declare methods that apply to a type
outside the type definition?
To illustrate, let's say we want to have a type of apple and want to push a
flavor to the array of flavors that characterizes an apple:
# define a type: Apple
type Apple
brand::ASCIIString
color::ASCIIString
flavors::Array{ASCIIString,1}
end
# a method designed to add flavors to the apple
function add_flavor(apple::Apple,flavor::ASCIIString)
push!(apple.flavors,flavor)
end
# create an instance of an AppleFuji = Apple("Fuji","red",["sweet"])
# add a flavor
add_flavor(Fuji, "sour")
Is this the way you'd do it in Julia?
In python I got used to putting methods that apply to "Apple" instances
inside the type definition where the keyword "self" would be used to add a
flavor: push!(self.flavors,flavor)
What would you say?
-Willem