|
| 1 | ++--------------------------------------+----------------------------+------------------------------------------------------------------+ |
| 2 | +| ``Root.Smell.ClassSmell.LargeClass`` | `Parent <../README.rst>`_ | `Index <//github.com/coala/aspect-docs/blob/master/README.rst>`_ | |
| 3 | ++--------------------------------------+----------------------------+------------------------------------------------------------------+ |
| 4 | + |
| 5 | ++---------------------+----------------------------------------+--------------------------------------------+ |
| 6 | +| **Sibling aspects** | `DataClump <../DataClump/README.rst>`_ | `FeatureEnvy <../FeatureEnvy/README.rst>`_ | |
| 7 | ++---------------------+----------------------------------------+--------------------------------------------+ |
| 8 | + |
| 9 | +LargeClass |
| 10 | +========== |
| 11 | +This aspect checks for large classes in your code base. A large class |
| 12 | +is a class that contains many fields, methods or lines of code. |
| 13 | + |
| 14 | +Tastes |
| 15 | +======== |
| 16 | + |
| 17 | ++--------------------------+--------------------------------------------------------------+--------------------------------------------------------------+ |
| 18 | +| Taste | Meaning | Values | |
| 19 | ++==========================+==============================================================+==============================================================+ |
| 20 | +| | | | |
| 21 | +|``max_class_length`` | Represents the max number of lines for a class's definition. | **999** + |
| 22 | +| | | | |
| 23 | ++--------------------------+--------------------------------------------------------------+--------------------------------------------------------------+ |
| 24 | +| | | | |
| 25 | +|``max_constants`` | Represents the max number of constants for a class | **3** + |
| 26 | +| | | | |
| 27 | ++--------------------------+--------------------------------------------------------------+--------------------------------------------------------------+ |
| 28 | +| | | | |
| 29 | +|``max_instance_variable`` | Represents the max number of instance variable for a class | **3** + |
| 30 | +| | | | |
| 31 | ++--------------------------+--------------------------------------------------------------+--------------------------------------------------------------+ |
| 32 | +| | | | |
| 33 | +|``max_methods`` | Represents the max number of method for a class | **3** + |
| 34 | +| | | | |
| 35 | ++--------------------------+--------------------------------------------------------------+--------------------------------------------------------------+ |
| 36 | + |
| 37 | + |
| 38 | +\* bold denotes default value |
| 39 | + |
| 40 | +Subaspects |
| 41 | +========== |
| 42 | + |
| 43 | +This aspect does not have any sub aspects. |
| 44 | + |
| 45 | +Example |
| 46 | +======= |
| 47 | + |
| 48 | +.. code-block:: Java |
| 49 | +
|
| 50 | + // This is large class given that the `max_class_length` is 20 |
| 51 | + |
| 52 | + public class Employee |
| 53 | + { |
| 54 | + private float salary; |
| 55 | + private float bonusPercentage; |
| 56 | + private EmployeeType employeeType; |
| 57 | + public Employee(float salary, float bonusPercentage, |
| 58 | + EmployeeType employeeType) |
| 59 | + { |
| 60 | + this.salary = salary; |
| 61 | + this.bonusPercentage = bonusPercentage; |
| 62 | + this.employeeType = employeeType; |
| 63 | + } |
| 64 | + public float CalculateSalary() |
| 65 | + { |
| 66 | + switch (employeeType) |
| 67 | + { |
| 68 | + case EmployeeType.Worker: |
| 69 | + return salary; |
| 70 | + case EmployeeType.Supervisor: |
| 71 | + return salary + (bonusPercentage * 0.5F); |
| 72 | + case EmployeeType.Manager: |
| 73 | + return salary + (bonusPercentage * 0.7F); |
| 74 | + } |
| 75 | + return 0.0F; |
| 76 | + } |
| 77 | + } |
| 78 | +
|
| 79 | +
|
| 80 | +Importance |
| 81 | +========== |
| 82 | + |
| 83 | +Refactoring these classes spares developers from the need to remember |
| 84 | +a large number of attributes and methods. Splitting these classes |
| 85 | +avoids duplication, and makes the code shorter and easier to maintain. |
| 86 | + |
| 87 | +How to fix this |
| 88 | +========== |
| 89 | + |
| 90 | +Usually splitting up those classes into many other classes solves the |
| 91 | +problem. |
| 92 | + |
0 commit comments