abstraction

Explain the Liskov Substitution Principle and data abstraction with Java examples.

Updated Feb 17, 2026
One-click install
npx skills add https://github.com/Objective-Arts/lens-dist --skill abstraction-objective-arts
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: abstraction
Source: https://github.com/Objective-Arts/lens-dist/tree/main/canon/abstraction
Command: npx skills add https://github.com/Objective-Arts/lens-dist --skill abstraction-objective-arts

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers understand and apply the Liskov Substitution Principle (LSP) and principles of data abstraction to write more robust, maintainable, and correct object-oriented code.

Core Features & Use Cases

  • LSP Explained: Deep dive into the Liskov Substitution Principle and its implications for inheritance and subtyping.
  • Data Abstraction: Learn about Abstract Data Types (ADTs), information hiding, and contracts.
  • Use Case: When designing a new class hierarchy, use this Skill to ensure your subtypes are truly substitutable for their base types, preventing common bugs and improving code reliability.

Quick Start

Explain the Liskov Substitution Principle and provide a simple Java code example illustrating a violation and a correct implementation.

Frequently Asked Questions about abstraction

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What is the Liskov Substitution Principle in object-oriented programming?

The Liskov Substitution Principle (LSP) defines behavioral subtyping, requiring that subtypes be completely substitutable for their base types without altering program correctness. It enforces adherence to class invariants, pre-conditions, and post-conditions within inheritance hierarchies.

How do I design a class hierarchy without violating LSP?

To apply LSP correctly, enforce strict behavioral contracts using Abstract Data Types (ADTs) and information hiding. Ensure derived classes do not strengthen pre-conditions or weaken post-conditions and class invariants, preventing unexpected runtime errors when substituting objects.

When do I need data abstraction and Abstract Data Types (ADTs)?

You need data abstraction and ADTs when defining robust module interfaces that hide implementation details. This technique isolates client code from internal representation changes, ensuring correct object-oriented design and enforcing strict behavioral contracts.

Why does my subclass break the program when overriding base class methods?

Overriding methods often breaks programs due to LSP violations, where the subtype alters expected behavior by violating class invariants or weakening post-conditions. Evaluating your hierarchy against Liskov's principles ensures proper behavioral subtyping and prevents these issues.

What is the difference between data abstraction and simple encapsulation?

Data abstraction defines behavior through Abstract Data Types (ADTs) and mathematical contracts, whereas simple encapsulation merely hides internal state. Data abstraction enforces strict pre-conditions and post-conditions, ensuring robust inheritance and correct behavioral subtyping.

Can I use LSP checklists to validate existing interface definitions?

Yes, you can validate existing interfaces using LSP checklists to verify behavioral subtyping. This process audits class invariants and contracts, ensuring your current inheritance hierarchies maintain robust substitutability and strict data abstraction.