Small Objects

Rafael A. George Duval
1 min readSep 10, 2022

--

Make smaller things. That’s all it is.

In object-oriented code, you have lots of little objects that send messages between them. Those messages give you a level of indirection that enables substitution between different objects.

Some programmers are afraid to make new objects. By adding more code in places with similar objects to what they’re trying to add. If the location already has an “if” statement, they put another branch on it. There’s a bargain to follow the pattern. If the design is a good one, the code gets better. If the way is a bad one, we exacerbate the problem.

Nobody adds a 10-line helper class to a 5000-line active record object.[¹]

Messages create boundaries or seams so that you can add behavior by replacing *role* acting objects. Make smaller classes, make smaller methods, and let them know as little about each other as possible.

[¹]: Sandi Metz(2014): RailsConf 2014 — All the Little Things (https://youtube.com/watch?v=8bZh5LMaSmE)

--

--

Rafael A. George Duval
Rafael A. George Duval

Written by Rafael A. George Duval

✍🏼 Building a Solo Digital Media Company 🧪 Snippets of Text [https://snippetsoftext.substack.com/subscribe]

No responses yet