File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -151,7 +151,7 @@ First Class Collections: a class that contains an array as an attribute should n
151151 ```
152152
1531535 . ** 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
You can’t perform that action at this time.
0 commit comments