I’ve been learning C# over the past while, and as a result, I’ve been learning a lot about Object Oriented Programming concepts. I have a rather good understanding of classes and inheritance and am about to learn about polymorphism, but one concept I currently can’t wrap my head around is encapsulation. I just can’t understand what it does or why it’s even used in any sense. Any help would be appreciated, because I’d rather move forward having a good understanding of every c# concept I’ve touched on so far before moving on to new things.
In: Other
Think of an object as a black box with a clearly defined interface on the outside. You don’t need to know what’s in the box to use it. For a large program, fitting together many black boxes is much less confusing than trying to build one enormous box.
Less confusing and also easier to make changes. If you open up a box and start changing the contents, you can be confident that you won’t break the program so long as you don’t change the interface. And adding new functionality is just a matter of figuring out what kind of box you’ll need and where to put it.
Latest Answers