Skip to main content

Sign in to CleanKata

Track your progress, earn XP, and unlock every lesson.

By signing in you agree to our Terms of Use and Privacy Policy.

Clean Code60 XP6 min

Placement & Statics

Put every function in the class most interested in it, and keep static methods truly stateless utilities.

Misplaced Responsibility

G17: Every piece of code should live where a reader would naturally look for it. When you write a method on Order that only reads Inventory data, you've misplaced it. The reader looking at Inventory won't find a method that belongs there. The method has a natural home — put it there. The rule of thumb: a method belongs in the class whose data it uses most.

Inappropriate Static Methods

G18: Static methods are fine for pure utilities that have no need for polymorphism — Math.round, String.format. They become a problem when the method should be polymorphic. If you have Order.calculateFee(order) as a static and tomorrow you need RushOrder to calculate fees differently, you're stuck. Instance methods support overriding; static methods do not. Reserve statics for operations that will never need specialization.

Code Challenge

Move the reorder_needed method to the Inventory class where it belongs.

💡Key takeaway

Put code where a reader would naturally look for it — in the class most interested in the data it uses.

🔧 Some exercises may still have errors. If something seems wrong, use the Feedback button (bottom-right of the page) to report it — it helps us fix it fast.

Hint: G17/G18: Ask which class is most interested in this data. Move the method there.

✗ Your version

Placement & Statics — CleanKata — CleanKata