Object Oriented Biology

Alex Dzwonchyk
Jul 25, 2017 · 6 min read
Source: https://cbmg.umd.edu/

One thing I’ve found helpful in learning new programming concepts is to come up with analogies to other unrelated ideas with which I’m already familiar. This lets me form a mental picture of the new concept I’m trying to understand, illustrating it so that I can see how the parts relate to one another.

This can be a great way to better understand the concepts themselves, and to create “chunks” which can then store new ideas in my long term memory effectively.

I just finished Launch School’s Object Oriented Programming course, and I often find myself thinking about OOP concepts in terms of biology, and imagining ways in which the two seem analogous to me.

Caveat: I don’t have a background in biology aside from some college courses, or really much of a deep understanding of the concepts at play there.

But what I think I remember about how cells work (and what Google reveals) has led me to some analogies about how classes and objects work in Ruby that I think are interesting enough to share.

So, here’s a stab at illustrating object oriented programming in terms of some drastically oversimplified cellular biology. Again, this is not meant to be an accurate representation of biology — only an attempt at providing a mental picture of the programming concepts being discussed.

Classes : DNA :: Objects : Cells

https://en.wikipedia.org/wiki/Algae#/media/File:Gephyrocapsa_oceanica_color.jpg

Objects are like plant or animal cells— objects are created from a class that acts as a “blueprint” or “mold,” just as cells are created from a genetic “blueprint”, usually in the form of DNA. Both genes and classes define the attributes and behaviors of the “objects” they create, and even though these objects or cells may have different internal “states”, they start off as copies generated from the same mold.

In Ruby, all classes, regardless of their specific definition, are sub-classes of class Object, which is the basic functional unit of object oriented programming.

Likewise, cells may be of “class” plant, animal, or fungi (for example), and then may belong to one of a multitude of sub-classes of those cell super-classes (neurons, intestinal cells, etc.), but they are all derived from class Cell — the basic structural unit of biological life.

class Neuron < HumanCell < AnimalCell < Cell

Sometimes cells need to use behaviors that they don’t inherit from their super-class — for example, some types of single-celled bacteria may be photosynthetic, and while the capability to generate energy from sunlight is found in plant cells and algae cells, bacteria are not sub-classed from either plants or algae.

So where did the bacteria get this photosynthetic behavior, if they didn’t inherit it from an “ancestor” in their class hierarchy? In this case, it’s almost as if the bacteria class in question is using a “mix-in” — adding a “module” for photosynthesis to their class definition!

Cell diagram showing mitochondria. Source: https://www.sciencelearn.org.nz/images/579-cell-diagram-showing-mitochondria

And just as cells have a cell wall that defines their boundaries, “encapsulating” the cell and protecting it from other cells and the outside world, class definitions define the boundaries of the objects they instantiate. In order to pass information into or out of an object after it’s been created, you must use that object’s public instance methods — much as you must use a cell’s receptors to pass information through its plasma membrane or cell wall.

Inside cells there are also processes that don’t need to interact with the outside world at all. For example, a cell may have some “private methods” called organelles (like the Golgi apparatus and mitochondria in the illustration above) which take care of the cell’s internal affairs, and don’t interface with anything outside the plasma membrane.

Multicellular Organisms : Cells :: Objects : Collaborator Objects

Sometimes a bunch of cells get together to form a multi-cellular organism. This only works because instead of having a long and complex set of instructions for every large and small behavior an organism should be capable of performing, all floating around together inside of one giant “cell” in a “procedural” mess of dependencies between interacting hormones, proteins, DNA, food, waste, and whatever else, different cells can instead specialize in specific operations, and only communicate with each other using the “interfaces” they expose to other cells for that purpose.

How does this happen?

Even though all of the cells in your human body descend from a HumanCell super-class, and look largely the same at the very beginning of their existence, when they’re first “instantiated”, they quickly diverge into specialties — muscle cells, skin cells, red blood cells, to name a few. It’s almost as if each type of cell has a “constructor method” specific to its “class,” that partially overrides whatever “initialization” instructions it inherits from its Cell super-class, and that is triggered when the Cell.new “command” is given — an example of nature’s “polymorphism” at work!

If we go up a level and imagine a multi-cellular organism as a collection of cell objects, it’s easy to think of an animal or plant as a collection of objects collaborating with one another as needed.

If you had an “initialize” method for a worm “class”, for example, it might have a set of “collaborator objects” that should be created when a worm zygote is “instantiated” during reproduction— instructions to the tune of “take this data input (genetic information), and use it to create X number of muscle cells, X number of digestive cells, X number of nerve cells, etc etc.”

A worm “object” could then be thought of as a collection of collaborator cell objects, encapsulated from one another on one level, and encapsulated together within the worm on another.

The Analogies Continue, and Break Down

Keith Holyoak, a UCLA professor of psychology and one of the world’s leading thinkers on analogical reasoning, recommends people ask themselves the following two questions in order to hone their skills: “What does this remind me of?” and “Why does it remind me of it?”

I’m much more interested in understanding object oriented programming well than I am in understanding cellular biology, so I’ve probably stretched a few of the ideas about cells mentioned above (though I’ve tried not to say anything demonstrably wrong).

Regardless, I think even attempting to create these analogies, even if they break down, is a highly effective way to learn new things, and it’s fun to see how far it can be taken. For example, I can imagine DNA as an array of 2 element sub-arrays, or maybe a hash with complementary key/value pairs of amino acids; protein created by DNA or RNA as some data that’s output from a cell “getter” method; Object#send as a kind of hormone receptor system; Error handling as an immune system response…you get the idea. Even if I’m oversimplifying the biology parts, I have a more concrete vision of these programming ideas I can refer to, which are otherwise mere abstractions.

Ultimately, what’s helpful about this exercise is that it allows me to better deconstruct object oriented programming into its fundamental principles by creating an imaginary space in which I can see how things work, while connecting this understanding to my existing mental frameworks —and ideally strengthening both in the process.

Launch School

Alex Dzwonchyk

Written by

Web developer & guitar player

Launch School

Publications of the Launch School Community

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade