Understanding Encapsulation in Coding

Quickly Grasp the Concept of Encapsulation

Arc Sosangyo
3 min read1 day ago
Photo by Annie Spratt on Unsplash

If you’re new to programming, chances are you’ll encounter this term during dev meetings but might not understand it. So, you just act cool and nod your head, pretending to know what it means. I’ve been there many times myself. Thankfully, my cover wasn’t blown before I finally understood what encapsulation really means.

Here’s how I understand encapsulation.

Imagine you’re Tony Stark (because, why not?), and you’ve just built the ultimate Iron Man suit. Do you let anyone access the suit’s inner mechanics? Nope! That would be reckless. You control who gets access to what, because some things (like the self-destruct mode or Jarvis’s sass settings) are private business.

In programming, encapsulation is the same idea. It’s about protecting your data and only letting the outside world interact with it in a controlled way.

Here’s the TL;DR of how it works:

  1. Keep some stuff private: Only the class (a.k.a. your code’s inner Iron Man suit) knows about certain details.
  2. Expose the right things publicly: Let outsiders interact with your class, but only through secure and polite doors.

Why Should You Care?

--

--

Arc Sosangyo
Arc Sosangyo

Written by Arc Sosangyo

Arc is an iOS Dev and app publisher, a former IT manager who transitioned to iOS engineering, and a big fan of AI, coding, science, history, and philosophy.

No responses yet