Avoiding Junk-Drawer Classes in Ruby

08-Feb-2019 1844
Because Ruby is an object-oriented language, we tend to model the world as a set of objects. We say that two integers (x and y) are a Point, and a Line has two of them.While this approach is often useful, it has one big problem. It privileges one interpretation of the data over all others. It assumes that x, and y will always be a Point and that you'll never need them to act as a Cell or Vector.What happens when you do need a Cell? Well, Point owns the data. So you add a your cell methods to Point. Over time you end up with a Point class that is a junk drawer of loosely-related methods.Junk-drawer classes are so common that we often accept them as inevitable and tack on a "refactoring" step to development. But what if we could avoid the problem in the first place?.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle