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
A method that requires more than 7 statements is simply doing too much or has too many responsibilities. It also requires the human mind to analyze the exact statements to understand what the code is doing. Break it down into multiple small and focused methods with self-explaining names, but make sure the high-level algorithm is still clear.
7
+
A method that requires more than 15 statements is simply doing too much or has too many responsibilities. It also requires the human mind to analyze the exact statements to understand what the code is doing. Break it down into multiple small and focused methods with self-explaining names, but make sure the high-level algorithm is still clear.
8
+
9
+
Also ensure that each method operates at a **single level of abstraction**. Mixing high-level functional calls (the "what") with low-level implementation details (the "how") in the same method makes it harder to understand the intent of the code.
10
+
11
+
```csharp
12
+
// Avoid: mixing abstraction levels in the same method
13
+
voidProcessOrder(Orderorder)
14
+
{
15
+
if (IsPremiumCustomer(order.CustomerId)) // functional; the "what"
16
+
{
17
+
ApplyDiscount(order);
18
+
}
19
+
20
+
if (Regex.IsMatch(order.Email.ToUpper().Trim(), @"^[^@]+@[^@]+\.[^@]+$")) // technical; the "how"
21
+
{
22
+
SendConfirmation(order.Email);
23
+
}
24
+
}
25
+
26
+
// Better: extract the technical detail behind an abstraction
0 commit comments