Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!