Skip to content

Commit b3ee108

Browse files
authored
Add AV0130: Apply the three pillars of object-oriented programming (#307)
1 parent 01259e1 commit b3ee108

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

_rules/0130.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
rule_id: 0130
3+
rule_category: general
4+
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

Comments
 (0)