# Building function (like OOP) inside a struct

**URL:** <https://discourse.julialang.org/t/building-function-like-oop-inside-a-struct/126180>\
**Category:** General Usage\
**Tags:** question\
**Created:** [February 22, 2025, 10:57am UTC](https://discourse.julialang.org/t/building-function-like-oop-inside-a-struct/126180 "2025-02-22T10:57:45Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 22, 2025, 11:15am UTC](https://discourse.julialang.org/t/building-function-like-oop-inside-a-struct/126180/2 "2025-02-22T11:15:49Z")

</div>

Short answer: don’t do this. Julia style is to do `method(object, args…)` and not `object.method(args…)`, and to define methods _outside_ of `struct` definitions (with the exception of [inner constructors](https://docs.julialang.org/en/v1/manual/constructors/#man-inner-constructor-methods)). Trying to force OOP syntax on Julia will lead to non-idiomatic code, [re-introduces the expression problem](https://www.youtube.com/watch?v=kc9HwsxE1OY), and [will be slow](https://docs.julialang.org/en/v1/manual/performance-tips/#Avoid-fields-with-abstract-type) if you’re not clever.

Long answer: see many previous discussions of this topic, e.g.:

- [Allowing the object.method(args...) syntax as an alias for method(object, args ...)](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051)
- [Do julia structs have member functions (and this-\>)](https://discourse.julialang.org/t/do-julia-structs-have-member-functions-and-this/8839)

---

_[View the full topic](https://discourse.julialang.org/t/building-function-like-oop-inside-a-struct/126180)._
