Abstract type, define it or not

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

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

I like to do it by

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

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

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.

3 Likes