Skip to content

Commit 720afbc

Browse files
docs: add interface boundary examples to implementation philosophy
Add good/bad examples showing why bypassing public interfaces creates fragile code. The fix for missing APIs is to extend the interface, not reach into internal state. Motivated by microsoft/amplifier-app-cli#70. 🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
1 parent 5fa3616 commit 720afbc

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

context/IMPLEMENTATION_PHILOSOPHY.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,30 @@ class EnhancedMcpClient:
295295
# [50+ more lines of complex state tracking and retry logic]
296296
```
297297

298+
### Bad Example: Bypassing Public Interfaces
299+
300+
```python
301+
# Reaching into internal state to access what should be exposed publicly
302+
def get_activator(resolver):
303+
# BAD: Unwrapping layers to find internal state
304+
bundle_resolver = getattr(resolver, "_bundle", resolver)
305+
activator = getattr(bundle_resolver, "_activator", None)
306+
return activator
307+
```
308+
309+
This pattern creates fragile code that breaks when implementations change. Each layer of "unwrapping" compounds the problem.
310+
311+
### Good Example: Respecting Interface Boundaries
312+
313+
```python
314+
# If you need access to something, extend the public interface
315+
def get_activator(resolver):
316+
# GOOD: Use public API (add one if it doesn't exist)
317+
return resolver.get_activator()
318+
```
319+
320+
**The rule**: If you can't do something through the public interface, the fix is to extend the interface—not bypass it. Accessing internal state (private attributes, wrapped objects) ties your code to implementation details that can change without warning.
321+
298322
## Remember
299323

300324
- It's easier to add complexity later than to remove it

0 commit comments

Comments
 (0)