Skip to content

Commit c3913bc

Browse files
authored
Clarify 'One Dot per Line' instruction (#499)
Clarify the 'One Dot per Line' rule to include Law of Demeter.
1 parent bbb5117 commit c3913bc

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

instructions/object-calisthenics.instructions.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ First Class Collections: a class that contains an array as an attribute should n
151151
```
152152

153153
5. **One Dot per Line**:
154-
- Limit the number of method calls in a single line to improve readability and maintainability.
154+
- Avoid violating Law of Demeter by only having a single dot per line.
155155

156156
```csharp
157157
// Bad Example - Multiple dots in a single line
@@ -160,11 +160,20 @@ First Class Collections: a class that contains an array as an attribute should n
160160
// Do something with userEmail
161161
}
162162
// Good Example - One dot per line
163+
public class User {
164+
public NormalizedEmail GetEmail() {
165+
return NormalizedEmail.Create(/*...*/);
166+
}
167+
}
168+
public class Order {
169+
/*...*/
170+
public NormalizedEmail ConfirmationEmail() {
171+
return User.GetEmail();
172+
}
173+
}
163174
public void ProcessOrder(Order order) {
164-
var user = order.User;
165-
var email = user.GetEmail();
166-
var userEmail = email.ToUpper().Trim();
167-
// Do something with userEmail
175+
var confirmationEmail = order.ConfirmationEmail();
176+
// Do something with confirmationEmail
168177
}
169178
```
170179

0 commit comments

Comments
 (0)