# Abstract type, define it or not

**URL:** <https://discourse.julialang.org/t/abstract-type-define-it-or-not/90983>\
**Category:** New to Julia\
**Created:** [November 29, 2022, 10:07am UTC](https://discourse.julialang.org/t/abstract-type-define-it-or-not/90983 "2022-11-29T10:07:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxchendt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxchendt/32/42976_2.png) [@maxchendt](https://discourse.julialang.org/u/maxchendt)\
**Post date:** [November 29, 2022, 10:07am UTC](https://discourse.julialang.org/t/abstract-type-define-it-or-not/90983/1 "2022-11-29T10:07:51Z")

</div>

I want to choose Float32, Float64, and BigFloat for computation ( speed and accuracy)

```julia
abstract type AbstractVariables{T <: AbstractFloat} end
mutable struct DefaultVariables{T} <: AbstractVariables{T}
    x::Vector{T}
end

```

I like to do it by

```julia
mutable struct DefaultVariables{T<: AbstractFloat} 
    x::Vector{T}
end

```

Which is better?  
When is it necessary to define an `abstract type` here?

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [November 29, 2022, 10:18am UTC](https://discourse.julialang.org/t/abstract-type-define-it-or-not/90983/2 "2022-11-29T10:18:48Z")

</div>

It’s necessary in two scenarios: firstly, if you want to define multiple subtypes of `AbstractVariables` and want to define generic methods that accept all subtypes, and secondly, if you expect other packages to subtype `AbstractVariables` and use the functions defined in your package.
