Skip to content

Use builder pattern for Instances of User construction. #7044

Description

@Neilk1021

Task Summary

Find all instances of positional User constructor and replace them with a .tap() based equivalent.

Context

Currently the jOOq table User is constructed like this when used:

  val GUEST: User =
    new User(null, "guest", null, null, null, null, UserRoleEnum.REGULAR, null, null, null, null)

This means whenever we change the jOOq definition we have to find all instances of this constructor and add / remove params even if they aren't needed. It's also just hard to read.

Instead, we could be using Scala's tap system which allows us to construct and setup an object in one pass. This is also considered more idiomatic Scala.

val GUEST: User = {
  new User().tap { user =>
    user.setName("guest")
    user.setRole(UserRoleEnum.REGULAR)
  }
}

Task Type

  • Refactor / Cleanup
  • DevOps / Deployment / CI
  • Testing / QA
  • Documentation
  • Performance
  • Other

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions