Program design: Types with only fixed Parameters?

florian
Sun, 31 Jan 2021 10:03:10 +0000
General Usage

Hi everyone, I’m trying to get used to programming with custom types and am in the following situation:
Suppose I want to write a Program that calls an API, and there are different types of calls.

First, I made a struct representing the call to the API:

struct APIRequest{T}
    type::T
    name::AbstractString
    query::AbstractString
    fields::NTuple
end

Now the difference (for now) between various types of calls is only the base URL. So my first thought was something like:

struct CallType1
    url::AbstractString
    ## Where the url is fixed, and should not have to be provided.
end

struct CallType2
    url::AbstractString
    ## Where the url is fixed, and should not have to be provided.
end

Is something like this considered bad design? I was trying to make use of multiple dispatch, because later functions may be different depending on the type of request.

2 posts - 2 participants