-
Notifications
You must be signed in to change notification settings - Fork 906
Commit 5efe631
committed
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!1 parent da716a7 commit 5efe631
2 files changed
+54
-20
lines changedLines changed: 6 additions & 20 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
41 | 41 |
| |
42 | 42 |
| |
43 | 43 |
| |
44 | - | ||
44 | + | ||
45 | 45 |
| |
46 | - | ||
47 | - | ||
48 | - | ||
49 | - | ||
50 | - | ||
51 | - | ||
46 | + | ||
52 | 47 |
| |
53 | 48 |
| |
54 | 49 |
| |
| |||
118 | 113 |
| |
119 | 114 |
| |
120 | 115 |
| |
121 | - | ||
122 | - | ||
123 | - | ||
124 | - | ||
125 | - | ||
116 | + | ||
126 | 117 |
| |
127 | 118 |
| |
128 | 119 |
| |
| |||
161 | 152 |
| |
162 | 153 |
| |
163 | 154 |
| |
164 | - | ||
165 | - | ||
166 | - | ||
167 | - | ||
168 | - | ||
169 | - | ||
170 | - | ||
155 | + | ||
156 | + | ||
171 | 157 |
| |
172 | 158 |
| |
173 | - | ||
159 | + | ||
174 | 160 |
| |
175 | 161 |
| |
176 | 162 |
| |
|
Lines changed: 48 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
96 | 96 |
| |
97 | 97 |
| |
98 | 98 |
| |
99 | + | ||
100 | + | ||
101 | + | ||
102 | + | ||
103 | + | ||
104 | + | ||
105 | + | ||
106 | + | ||
107 | + | ||
108 | + | ||
109 | + | ||
110 | + | ||
111 | + | ||
112 | + | ||
113 | + | ||
114 | + | ||
115 | + | ||
116 | + | ||
117 | + | ||
118 | + | ||
99 | 119 |
| |
100 | 120 |
| |
101 | 121 |
| |
| |||
110 | 130 |
| |
111 | 131 |
| |
112 | 132 |
| |
133 | + | ||
134 | + | ||
135 | + | ||
136 | + | ||
137 | + | ||
138 | + | ||
139 | + | ||
140 | + | ||
113 | 141 |
| |
114 | 142 |
| |
115 | 143 |
| |
| |||
127 | 155 |
| |
128 | 156 |
| |
129 | 157 |
| |
158 | + | ||
159 | + | ||
160 | + | ||
161 | + | ||
162 | + | ||
163 | + | ||
164 | + | ||
165 | + | ||
166 | + | ||
167 | + | ||
168 | + | ||
169 | + | ||
170 | + | ||
171 | + | ||
172 | + | ||
173 | + | ||
130 | 174 |
| |
131 | 175 |
| |
132 | 176 |
| |
| |||
178 | 222 |
| |
179 | 223 |
| |
180 | 224 |
| |
225 | + | ||
226 | + | ||
227 | + | ||
228 | + | ||
181 | 229 |
| |
182 | 230 |
| |
183 | 231 |
| |
|
0 commit comments