Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions _rules/0130.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
rule_id: 0130
rule_category: general
title: Apply the four pillars of object-oriented programming
severity: 2
---
Object-oriented design rests on four fundamental concepts. Understanding and applying them correctly is essential to writing maintainable code:

- **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)).
- **Abstraction**: model the essential characteristics of a concept, ignoring irrelevant details. Good abstractions hide complexity and provide stable, meaningful interfaces.
- **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)).
- **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)).

These are tools, not goals. Apply them where they add clarity and maintainability.