Julia: OOP or not

后端 未结 6 1079
难免孤独
难免孤独 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:35

    Yes. You just can't inherit from concrete "classes" with fields, only from abstract ones. This is because the memory layout of a concrete struct in Julia is part of its interface, and being able to subclass it by adding fields would break the Liskov substitution principle.

    However, Functions with multiple dispatch are a strict generalization of methods with single dispatch and are strictly more polymorphic. You just have to define them outside of a class definition, because they can "belong" to multiple objects.

    Traditional methods in an OO language are a special case of Julia functions where you only have dispatching based on the first argument.

提交回复
热议问题