On Classes

Karan Chawla / April 21, 2021

1 min read

Loosening encapsulation is always the last resort.

The first rule of classes is that they should be small. The second rule of classes is that they should be smaller than that.

Responsibilities is the measure through which we judge the size of a class.

  • The name of the class should describe the responsibilities it fulfills. In fact, naming is probably the first way of helping determine class size.

Open-Closed Principle — Also known as OCP. Classes should be open for extension but closed for modification.

Isolating from change — Dependency Inversion Principle states that our classes should depend upon abstractions, not on concrete details.

Subscribe to the newsletter

Get emails from me about future of technology, philosophy, and human behavior.

- subscribers