Software Encapsulation Simplified.

Imagine for a minute you own a restaurant. ..

What would happen if you allowed the customers to come into the kitchen while the chefs were preparing their food AND tell the chefs how to cook it?

CHAOS

In the same way a restaurant ...

🧵👇
2/ protects its operations from the customer through menus, servers, etc we too must protect our software.

Software encapsulation allows us to do just that.

We can do this by only exposing what we want through language features like access modifiers (public, private, etc)
3/ We allow other parts of the program (the customers) to talk to our part (the chefs and kitchen staff) by exposing members in a deliberate way.

This control helps prevent any side effects that may occur from allowing other parts of the program to do too much to our part.
4/ For example...

We could expose a single public method on the hypothetical kitchen object ...

kitchen.ReceiveOrder(order);

Did this help you understand encapsulation?
Let me know!
You can follow @eamokeane.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: