I'm working on Juno with Julia.
I don't know if Julia supports OOP or not.
For example, is there something like class
or struct
of c++?
How to declare it with members such as a data or a function?
Julia is not object-oriented in the full sense because you cannot attach methods to Julia's objects ("types"). The types do seem very similar to objects though. However, since they do not have their own associated methods and there is no inheritance the objects themselves don't do the acting.
Julia does not have classes in the object-oriented sense as it is not an object-oriented language. The main paradigm of Julia which replaces object-oriented programming is multiple dispatch, see here.
Julia is a multi-paradigm language — and that includes support for object-oriented sorts of patterns.
Julia does not have classes. Instead we define new types and then define methods on those types. Methods are not "owned" by the types they operate on. Instead, a method can be said to belong to a generic function of the same name as the method.
When in doubt, read the documentation...
https://docs.julialang.org/en/v1/manual/types/#Composite-Types-1
Long story short:
struct MyType a::Int64 b::Float64 end x = MyType(3, 4) x.a
EDIT: Methods are defined outside the type definition, e.g.
function double(x::MyType) x.a *= 2 end
Methods do not live inside the type, as they would do in C++ or Python, for example. This allows one of the key features of Julia, multiple dispatch, to work also with user-defined types, which are on exactly the same level as system-defined types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With