Encapsulation
This concept entails one of the most important aspects of OOP: the maintenance of the object’s state.
Earlier, in Figure A1.3, I presented a circle with a set of properties with values that describe the circle you’re seeing. As your program runs, it’s likely those properties will change in response to events within that program. If you take a snapshot of that circle at any point in time during your program’s execution, you can talk about its current state. It’s currently sporting a radius of 200 pixels, with a line color of black, and fill color of dark gray. Let’s create some code to represent our circle in the simplest way possible, without any encapsulation, so we can see it added later:
public class Circle { ushort centerX; ushort centerY; ushort radius; byte lineWidth; string lineColor; string fillColor; }
In this listing, we create a Circle
...