In several places of the code base I am working in, I see classes with these kinds of properties:
public class LinkEnd
{
public Joint AssociatedJoint { get; set; }
public Point Location
{
get
{
return AssociatedJoint.Location;
}
set
{
AssociatedJoint.Location = value;
}
}
...
}
Is there a formal term for this pattern of exposing a property of a property? I understand getters and setters, I am specifically interested in if there is a term describing a class representing a property as one of its own and backing that property with another encapsulated object's property.
I think that you are not looking for a pattern but rather rule - law of demeter.
More: http://en.wikipedia.org/wiki/Law_of_Demeter
Note that it doesn't mean you always can't access properties of other object directly. You just shouldn't access properties of different abstraction levels.
In example: what is better approach?
digestive_system = person.digestive_system()
stomach = digestive_system.stomach()
stomach.put(food)
versus
person.eat(food)
It's clear.
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