Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
Handling a class with a large amount of of parameters?

So i'm having a hard time with handling a large amount of class properties. Im making a "component" and want to make this "component" as customizable as possible. In doing so, I end up having to deal with this:

     constructor({
        embeds = [],
        message = null,
        client = null,
        isSelectable = false,
        skip = true,
        timeout = 10000,
        isCallback = true,
        max = 10,
        results = [],
        hasPageNumber = true,
        start = 0,
        identifiers = ['1️⃣','2️⃣','3️⃣','4️⃣','5️⃣','6️⃣','7️⃣','8️⃣','9️⃣','🔟','1️⃣1️⃣','1️⃣2️⃣','1️⃣3️⃣','1️⃣4️⃣','1️⃣5️⃣','1️⃣6️⃣','1️⃣7️⃣','1️⃣8️⃣','1️⃣9️⃣','2️⃣0️⃣'],
        undefinedResultValue = 'Unknown Result',
        useIdentifiers = true,
        innerPageOptions = {
            message: message,
            client: client,
            hasPageNumber: hasPageNumber,
            skip: skip,
            timeout: timeout,
            start: start,
            isSelectable: isSelectable,
            embeds: null
        }
    })

The code above works fine but is horrible to looks at and I feel people have encountered similar issues to this. I want to limit the number of properties whilst also making the "component" as customizable as possible. Im also trying to heavily focus on making my code as clean as possible and dont really have anyone to help out with these types of issues and is were experience is needed to solve.

Each property is used, some more than others and some with more affect. I thought about collapsing some values into another sub-object but this just is an alternate outcome that is very similar to what I already have.

Class structure for more detail on what I have, class methods have been excluded due to being obselete for this problem:

export class PageEmbed{
    constructor(options: Options | SearchOptions)
    private options: Options | SearchOptions
    private content: MessageEmbed[]
    private display: SearchDisplayProperties
    private index: number
}

export class Page extends PageEmbed{
    constructor(options: PageOptions)
    private message : Message
}

export class SearchPage extends PageEmbed{
    constructor(_options: SearchOptions)
    private inner: Options
    public page: Page
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could look for some common or default parameters combinations and add them somewhere in your code. Also you could implement the factories to simplify the instances creation. The general idea is:

const DEFAULT_PROPS = {
    embeds = [],
    message = null,
    client = null,
    isSelectable = false,
    skip = true,
    timeout = 10000,
    isCallback = true,
    max = 10,
    results = [],
    hasPageNumber = true,
    start = 0,
}

class MyFactory {
    props = DEFAULT_PROPS

    mutate (newProps) {
        this.props = {
            ...this.props,
            ...newProps
        }
        return this
    }

    create() {
        return new MyClassWithProps (this.props)
    }

}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda