Julia: OOP or not

后端 未结 6 1083
难免孤独
难免孤独 2021-02-01 00:46

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+

6条回答
  •  梦谈多话
    2021-02-01 01:48

    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. Instead you have functions which act on the objects.

    The difference is ball.checkCollision() vs checkCollision(ball,Walls). In reality it's not that big of a deal. You can make something like inheritance by having a type have a field of another type, and multiple dispatch lets you write functions which do different things based on the objects you give them, which can be almost like object methods. The real difference is where you save the function and types in a file. So you can do a kind of quasi-objected-oriented style in Julia, but it's still distinctly different than OOP languages.

提交回复
热议问题