
Episode 3 · Season 14
A Practical Approach to Data Encapsulation
About this episode
We have developed many bad habits over the years as OOP has proliferated frameworks and tools. In this episode, we look at the practical side of data encapsulation and access levels like private, protected, and public.
Tools Are A Beginning
Modern frameworks and tools provide ways to generate a general object-oriented solution quickly. Therefore, the tools will give us a start, but not the best solution. There are too many details the tools are not privy to that are essential to the best solution. We will make the best use of tools when we remember this fact. That means we can not only move forward with generated code. We must review what is provided and extend or remove details to fit our needs.
A perfect example of tools being a less-than-perfect fit is in data hiding. There are general assumptions made for accessors like getters and setters that should be refined. A solution does not know that you have a read-only property or one that should not be directly passed through on a request.
Data Encapsulation in a Nutshell
The goal of data encapsulation is for us to provide a form of just-in-time access to data within our system. This approach can also be viewed as making attributes and methods available on a need-to-know (or need-to-use) basis. Once we expose a method or value, we can not undo that. There are plenty of examples in frameworks where a feature or value is deprecated. That occurs when something was exposed that now should not be. Thus, the author is warning users that the deprecated element will be disappearing in the future. An ideal approach would be not to expose that feature in the first place.
More from Develpreneur: Become a Better Developer and Entrepreneur
A handful of people love your MVP. Their suggestions keep coming, and AI helps you turn those requests into working features quickly. The product is growing. Whether it is growing in the right directi…
Your team can generate an interface faster than ever. Meanwhile, customers are still staring at confusing error messages, waiting for pages to load, and trying to figure out what happens after they cl…
After a year of deadlines, long hours, and projects that seemed determined to last forever, Thanksgiving offers a chance to pause and enjoy what all that effort has made possible. In this Thanksgiving…
The holiday is almost here, but your brain is still at work. There is something to finish, something to check, and probably something you could squeeze in before everyone arrives. Closing the laptop s…
Building a successful business requires more than developing a great product. As companies grow, they face new challenges involving customer expectations, operational efficiency, financial decisions,…