Original Post
Does this code violates the Law of Demeter?
The function foo() calls a function on object string s1, which returns s2 to be further processed in this function...This looks like violating the Demeter law since it calls functions on an object
returned by another function. If so then what should be the alternative?
Thanks.
void object::foo()
{
//...
std::string s1 = "Hello World!";
string s2 = s1.substr(0, 5);
// process string s2...
//.....
}
The function foo() calls a function on object string s1, which returns s2 to be further processed in this function...This looks like violating the Demeter law since it calls functions on an object
returned by another function. If so then what should be the alternative?
Thanks.