Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda