| Conditions | 13 |
| Total Lines | 26 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Complex classes like boolean_algebra.boolean() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | OPERATION_NAMES = ( |
||
| 10 | def boolean(x, y, operation): |
||
| 11 | if operation == 'conjunction': |
||
| 12 | if x and y: |
||
| 13 | return 1 |
||
| 14 | else: |
||
| 15 | return 0 |
||
| 16 | elif operation == 'disjunction': |
||
| 17 | if x or y: |
||
| 18 | return 1 |
||
| 19 | else: |
||
| 20 | return 0 |
||
| 21 | elif operation == 'implication': |
||
| 22 | if x: |
||
| 23 | return y |
||
| 24 | else: |
||
| 25 | return 1 |
||
| 26 | elif operation == 'exclusive': |
||
| 27 | if x == y: |
||
| 28 | return 0 |
||
| 29 | else: |
||
| 30 | return 1 |
||
| 31 | elif operation == 'equivalence': |
||
| 32 | if x == y: |
||
| 33 | return 1 |
||
| 34 | else: |
||
| 35 | return 0 |
||
| 36 | |||
| 46 |