Senior
How to make an Increaser universal — not tied to the number 100?
sobes.tech AI
Answer from AI
To make the Increaser universal and not tied to the number 100, you need to parameterize this value. For example, you can pass the maximum value or the step size as an argument to the function or structure field. This will allow using the Increaser with any numbers, not just 100.
Example in Go:
package main
import "fmt"
type Increaser struct {
max int
value int
}
func NewIncreaser(max int) *Increaser {
return &Increaser{max: max, value: 0}
}
func (inc *Increaser) Increase() {
if inc.value < inc.max {
inc.value++
}
}
func main() {
inc := NewIncreaser(200) // now the maximum is 200, not 100
for i := 0; i < 205; i++ {
inc.Increase()
fmt.Println(inc.value)
}
}
This approach makes it easy to change the limit without modifying the Increaser code.