I read a long time ago about a rule that using an object we shouldn't point from one class to the other due to null possibility.
class Foo
{
public Bar Bar1 {get; set;}
public Foo()
{
}
}
class Bar
{
public string Name{ get; set;}
}
Foo foo = new Foo();
foo.Bar1.Name;
what is the law or rule called after this pattern?
It's the Law of Demeter
To quote some of it:
In particular, an object should avoid invoking methods of a member object returned by another method. For many modern object oriented languages that use a dot as field identifier, the law can be stated simply as "use only one dot". That is, the code a.b().Method() breaks the law where a.Method() does not.
I think your referring to the Law of Demeter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With