You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Apply the four pillars of object-oriented programming
5
+
severity: 2
6
+
---
7
+
Object-oriented design rests on four fundamental concepts. Understanding and applying them correctly is essential to writing maintainable code:
8
+
9
+
-**Encapsulation**: hide implementation details behind a well-defined interface. Expose only what callers need, and protect internal invariants (see [AV1025](#{{ site.default_rule_prefix }}1025) and [AV1026](#{{ site.default_rule_prefix }}1026)).
10
+
-**Abstraction**: model the essential characteristics of a concept, ignoring irrelevant details. Good abstractions hide complexity and provide stable, meaningful interfaces.
11
+
-**Inheritance**: share behavior by forming "is-a" relationships between types. Use sparingly — prefer composition when the relationship is primarily about code reuse rather than substitutability (see [AV0110](#{{ site.default_rule_prefix }}0110)).
12
+
-**Polymorphism**: let objects of different types be treated through a common interface. Prefer polymorphism over type-checking and casting (see [AV1011](#{{ site.default_rule_prefix }}1011) and [AV1013](#{{ site.default_rule_prefix }}1013)).
13
+
14
+
These are tools, not goals. Apply them where they add clarity and maintainability.
0 commit comments