From c3913bc6db7e64ee27fda14c595a8b9c13cf02da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Truds=C3=B8=20Mahon?= Date: Thu, 18 Dec 2025 23:09:43 +0100 Subject: [PATCH] Clarify 'One Dot per Line' instruction (#499) Clarify the 'One Dot per Line' rule to include Law of Demeter. --- .../object-calisthenics.instructions.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/instructions/object-calisthenics.instructions.md b/instructions/object-calisthenics.instructions.md index dcc1ff9f..a1f4b3be 100644 --- a/instructions/object-calisthenics.instructions.md +++ b/instructions/object-calisthenics.instructions.md @@ -151,7 +151,7 @@ First Class Collections: a class that contains an array as an attribute should n ``` 5. **One Dot per Line**: - - Limit the number of method calls in a single line to improve readability and maintainability. + - Avoid violating Law of Demeter by only having a single dot per line. ```csharp // 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 // Do something with userEmail } // Good Example - One dot per line + public class User { + public NormalizedEmail GetEmail() { + return NormalizedEmail.Create(/*...*/); + } + } + public class Order { + /*...*/ + public NormalizedEmail ConfirmationEmail() { + return User.GetEmail(); + } + } public void ProcessOrder(Order order) { - var user = order.User; - var email = user.GetEmail(); - var userEmail = email.ToUpper().Trim(); - // Do something with userEmail + var confirmationEmail = order.ConfirmationEmail(); + // Do something with confirmationEmail } ```