Ir al contenido

God Class (ARCH5189)

Esta página aún no está disponible en tu idioma.

Key go.quality.god-struct · Severity warning · Category quality

Structs carrying many fields and methods take on multiple responsibilities, lower cohesion, and become hard to change. Split them by responsibility.

type App struct {
db, cache, mailer, logger, auth, billing, search, queue any
}
func (a *App) CreateUser() {}
func (a *App) SendEmail() {}
func (a *App) Charge() {}
func (a *App) Index() {}
// ... dozens of unrelated methods
type UserService struct{ db, cache any }
func (s *UserService) Create() {}
type BillingService struct{ db any }
func (s *BillingService) Charge() {}

Split the struct into focused, smaller types following the single-responsibility principle.