Long Method (ARCH4180)
Esta página aún no está disponible en tu idioma.
Key java.quality.long-method · Severity info · Category quality
Overly long methods take on more than one responsibility and become hard to read and test. Split the logic into well-named helper methods.
Incorrect
Section titled “Incorrect”void processOrder(Order o) { validate(o); // 40+ lines: pricing, tax, discount, // inventory deduction, invoice, email, logging... double tax = o.total() * 0.18; double discount = o.total() > 1000 ? 0.1 : 0; inventory.deduct(o.items()); invoices.create(o, tax, discount); mailer.send(o.customerEmail(), buildBody(o)); audit.log("order " + o.id());}Correct
Section titled “Correct”void processOrder(Order o) { validate(o); Pricing p = price(o); inventory.deduct(o.items()); invoices.create(o, p); notify(o);}Break the method into small, named helpers that each do one thing.