liskov
Skill2 starsChanged 42 days agoMITView on GitHub
Barbara Liskov's principles of data abstraction and substitutability: hide representation behind a clear abstraction, and make sure anything that claims to be a subtype or implementation can stand in for the original without surprising its callers. Use when designing interfaces, inheritance, plugins, adapters, repository or storage layers, API versions, or when a "drop-in replacement" keeps breaking callers. Triggers: "think like Liskov", "substitutability", "LSP", "interface design", "can I swap this", "คิดแบบลิสคอฟ", "ออกแบบ interface". Not for one-off scripts.
In this repository25 other files it gives its agents.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 22
Not affiliated with or endorsed by Barbara Liskov.
- Distinctive: line 38
No new exceptions or side effects that callers don't expect
- Distinctive: line 50
Write in the user's language.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Think like Liskov
Turing Award winner (2008) for foundations of data abstraction and distributed computing. With Jeannette Wing she defined behavioral subtyping: a subtype is only a subtype if every program written against the supertype still behaves correctly with it.
Not affiliated with or endorsed by Barbara Liskov. Built from her published papers listed below.
When to use
- Adding a new implementation behind an existing interface (another payment provider, another storage backend)
- Inheritance hierarchies, base classes, overrides
- Changing an API that other code or other teams depend on
- Callers are full of
if (x instanceof Special)checks
Method
- Write the abstraction's contract from the caller's side: what callers may assume about inputs, outputs, errors, side effects, ordering, performance class, and invariants. Representation details are not part of it.
- Check each implementation or subtype against the contract:
- Preconditions: may only be the same or weaker (accept at least what the parent accepts)
- Postconditions: the same or stronger (promise at least what the parent promises)
- Invariants of the parent: preserved
- No new exceptions or side effects that callers don't expect
- History: no state changes the parent's callers couldn't cause
- Look for leaks: callers that type-check, cast, or branch on the concrete type are proof the abstraction is leaking or the hierarchy is wrong.
- Fix the model, not the callers: split the interface, make the special behavior explicit in the contract, or use composition instead of inheritance.
- Make substitution testable: one shared contract test suite that every implementation must pass.
Output
Contract (caller's view):short listImplementation check:table of implementation × rule → ok / violation with the concrete caseLeaks found:caller locations that depend on the concrete typeChange:the interface or hierarchy fix, plus the shared contract test- Write in the user's language.
Anti-patterns
- Overriding a method to throw "not supported"
- A subclass that tightens what it accepts (rejects inputs the parent took)
- Exposing the representation (raw rows, internal maps) through the abstraction
- "Drop-in replacement" claims with no shared tests
Example (illustration)
User: We added
S3Storagenext toLocalStorage. Some uploads now fail in production.Contract (caller's view):
put(key, bytes)thenget(key)returns the same bytes immediately; keys may contain/;deleteof a missing key is a no-op.Implementation check:
S3Storage.deleteof a missing key throws (violation: new exception). Keys with a leading/create an empty path segment in S3 (violation: precondition got stricter).Leaks found:
if (storage instanceof S3Storage) key = key.slice(1)in two controllers.Change: normalize keys inside
S3Storage, makedeleteidempotent, remove the twoinstanceofchecks, addstorage.contract.test.tsrun against both implementations.
Sources
- Barbara Liskov and Jeannette Wing, "A Behavioral Notion of Subtyping", ACM TOPLAS, 1994: https://doi.org/10.1145/197320.197383
- Barbara Liskov, "Data Abstraction and Hierarchy", keynote address at OOPSLA '87: https://doi.org/10.1145/62139.62141
- ACM A.M. Turing Award citation, 2008: https://amturing.acm.org/award_winners/liskov_1108679.cfm
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

