# Parametric or normal types for dispatching on materials

**URL:** <https://discourse.julialang.org/t/parametric-or-normal-types-for-dispatching-on-materials/61808>\
**Category:** Modelling & Simulations\
**Tags:** question, parametric-types\
**Created:** [May 25, 2021, 7:42pm UTC](https://discourse.julialang.org/t/parametric-or-normal-types-for-dispatching-on-materials/61808 "2021-05-25T19:42:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)\
**Post date:** [May 25, 2021, 7:42pm UTC](https://discourse.julialang.org/t/parametric-or-normal-types-for-dispatching-on-materials/61808/1 "2021-05-25T19:42:22Z")

</div>

When generating a type representing a material would it be better to generate types for every material or to create a parametric material type.

What would you suggest and why?

```julia
abstract type Material end
struct Gold <: Material end
isMetal(::Gold) = true

```

```julia
struct Material{T} end
const Gold = Material{:Gold}
isMetal(::Gold) = true

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 27, 2021, 5:54am UTC](https://discourse.julialang.org/t/parametric-or-normal-types-for-dispatching-on-materials/61808/2 "2021-05-27T05:54:42Z")

</div>

Unless you want to compile specific code for each material, I would just store properties in a `struct`. Eg

```julia
struct Material
    is_metal::Bool
    # ... surely it has other fields
end
const Gold = Material(true) # look at Base.@kwdef

```

See

[https://docs.julialang.org/en/v1/manual/performance-tips/#The-dangers-of-abusing-multiple-dispatch-(aka,-more-on-types-with-values-as-parameters)](https://docs.julialang.org/en/v1/manual/performance-tips/#The-dangers-of-abusing-multiple-dispatch-(aka,-more-on-types-with-values-as-parameters))
