Encapsulation

Object-Oriented Programming

Object-oriented programming is a way of organising code around self-contained building blocks called objects. Each object is responsible for one thing — its own data and its own behaviour — instead of spreading that responsibility across the entire program.

Why It Matters#

As programs grow, keeping all the code in one place becomes unmanageable. A single file with hundreds of lines is hard to read, hard to change, and easy to break.

Property (C#)

A property in C# is a member of a class that provides controlled access to a value. It looks like a variable when you use it, but it’s backed by get and set accessors that control how the value is read and written.

Auto-Property#

The simplest form is the auto-property. The compiler generates the backing storage automatically.

public class Player
{
    public int WinCount { get; set; }
}
  • get — allows the value to be read
  • set — allows the value to be written

Using it looks exactly like using a variable: