# Application Code Organization

**URL:** <https://discourse.julialang.org/t/application-code-organization/53224>\
**Category:** New to Julia\
**Tags:** code-organization\
**Created:** [January 12, 2021, 3:02pm UTC](https://discourse.julialang.org/t/application-code-organization/53224 "2021-01-12T15:02:11Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [January 12, 2021, 6:40pm UTC](https://discourse.julialang.org/t/application-code-organization/53224/15 "2021-01-12T18:40:10Z")

</div>

> [@Nathan\_Boyer](#):
>
> Would you just set fields to `nothing` if a file does not exist?

That is one alternative. Another is to let the structure types “invisible” to the user. For example:

This would be implemented in the package:

```julia
julia> struct WithFile
         f :: String
       end

julia> struct WithoutFile
       end

julia> preprocess_data() = return WithoutFile()
preprocess_data (generic function with 1 method)

julia> preprocess_data(f::String) = return WithFile(f)
preprocess_data (generic function with 2 methods)

julia> compute(data::WithoutFile) = "Computation without file"
compute (generic function with 1 method)

julia> compute(data::WithFile) = "Computation with file: $(data.f)"
compute (generic function with 2 methods)

```

The “user” starts here:

```julia
julia> user_data_without_file = preprocess_data()
WithoutFile()

julia> compute(user_data_without_file)
"Computation without file"

julia> user_data_with_file = preprocess_data("file.data")
WithFile("file.data")

julia> compute(user_data_with_file)
"Computation with file: file.data"

```

> [@Nathan\_Boyer](#):
>
> There is no such thing as methods for `struct` s right?

Actually there are, the [`functors`](https://docs.julialang.org/en/v1/manual/methods/#Function-like-objects).

---

_[View the full topic](https://discourse.julialang.org/t/application-code-organization/53224)._
