You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: eliminate isinstance() checks with pure polymorphism
Replace all isinstance() type checking with proper polymorphic methods:
Pure Polymorphism Methods:
- get_summary_info(): Each class returns its own summary format
- is_single_file(): Boolean check without isinstance()
- gather_contents(): Recursive content gathering via method dispatch
- get_display_name(): Tree display formatting (/, -> target, etc.)
- has_children(): Check for child nodes without type checking
Benefits:
- No isinstance() 'clochard' style code anywhere
- True duck typing - just call methods and let Python dispatch
- Cleaner, more maintainable code
- Each class encapsulates its own behavior
- Easy to extend with new node types
Code Changes:
- FileSystemNode: Base implementations for all methods
- FileSystemFile: is_single_file()=True, summary with line count
- FileSystemDirectory: get_display_name() adds '/', has_children() checks list
- FileSystemSymlink: get_display_name() shows '-> target'
- output_formatter.py: Use polymorphic methods instead of isinstance()
This is proper OOP - objects know their own behavior!
0 commit comments