Three independently ugly bugs that all fed the same log flood:
* Electron's `WebFrameMain.send` writes every "Render frame was disposed"
to stderr via `console.error`. When the worker fans a second
agent-event past a reloading renderer, we produced thousands of
identical lines and stalled the main loop on stderr I/O. Added a
`mainFrame.detached` guard so the send is short-circuited before
Electron's own catch block fires, and installed a targeted filter in
`suppress-warnings.ts` (now actually imported from the entry point)
so the specific `console.error("Error sending from webFrameMain:"…)`
noise never reaches the terminal. Any other payload still surfaces.
* `dispatchAgentMessage` accepted the human-reader sentinel as a wake
target when an agent replied to `__board__` — `wakeAgentIfPossible`
then called `db.getAgent("__board__")`, threw, and the dispatcher
kept repeating on every send. Strip `HUMAN_SENDER_ID` at
`resolveMessageWakeTargets`, and keep a defense-in-depth guard in the
heartbeat so a stray caller (future automation fan-out) cannot
reintroduce the crash.
* Pi's skills loader rejects any SKILL.md whose frontmatter `name`
diverges from its parent directory. The four bundled `my-writing-style`
copies declared `name: writing-style-skill`, so every install emitted
a warning and dropped the skill. They also lived as orphan gitlinks
(mode 160000 without .gitmodules), and the global `*.md` gitignore
hid every other SKILL.md from version control. Fixed the frontmatter
to match the dir, converted the dangling submodules to plain trees,
and allowlisted `builtin-skills/**/*.md` so a fresh clone carries the
catalogue instead of silently losing it.
77 lines
2.1 KiB
Markdown
77 lines
2.1 KiB
Markdown
---
|
|
title: Isolate Classes from Change
|
|
impact: MEDIUM
|
|
impactDescription: enables testing and reduces coupling
|
|
tags: class, dip, interfaces, coupling
|
|
---
|
|
|
|
## Isolate Classes from Change
|
|
|
|
Depend on abstractions, not concretions. Classes should depend on interfaces rather than concrete implementations. This enables testing and reduces the impact of change.
|
|
|
|
**Incorrect (depends on concrete implementation):**
|
|
|
|
```java
|
|
public class Portfolio {
|
|
private NYSEStockExchange exchange;
|
|
|
|
public Portfolio(NYSEStockExchange exchange) {
|
|
this.exchange = exchange;
|
|
}
|
|
|
|
public Money value() {
|
|
Money total = Money.ZERO;
|
|
for (String symbol : holdings.keySet()) {
|
|
// Cannot test without real stock exchange connection
|
|
total = total.plus(exchange.currentPrice(symbol)
|
|
.times(holdings.get(symbol)));
|
|
}
|
|
return total;
|
|
}
|
|
}
|
|
```
|
|
|
|
**Correct (depends on abstraction):**
|
|
|
|
```java
|
|
public interface StockExchange {
|
|
Money currentPrice(String symbol);
|
|
}
|
|
|
|
public class Portfolio {
|
|
private StockExchange exchange;
|
|
|
|
public Portfolio(StockExchange exchange) {
|
|
this.exchange = exchange;
|
|
}
|
|
|
|
public Money value() {
|
|
Money total = Money.ZERO;
|
|
for (String symbol : holdings.keySet()) {
|
|
total = total.plus(exchange.currentPrice(symbol)
|
|
.times(holdings.get(symbol)));
|
|
}
|
|
return total;
|
|
}
|
|
}
|
|
|
|
// Production
|
|
Portfolio portfolio = new Portfolio(new NYSEStockExchange());
|
|
|
|
// Testing
|
|
@Test
|
|
public void portfolioValueShouldSumAllHoldings() {
|
|
StockExchange mockExchange = mock(StockExchange.class);
|
|
when(mockExchange.currentPrice("AAPL")).thenReturn(Money.dollars(150));
|
|
|
|
Portfolio portfolio = new Portfolio(mockExchange);
|
|
portfolio.add("AAPL", 10);
|
|
|
|
assertEquals(Money.dollars(1500), portfolio.value());
|
|
}
|
|
```
|
|
|
|
**Dependency Inversion Principle (DIP):** High-level modules should not depend on low-level modules. Both should depend on abstractions.
|
|
|
|
Reference: [Clean Code, Chapter 10: Classes](https://www.oreilly.com/library/view/clean-code-a/9780136083238/)
|