Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to describe this code pattern?

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.

like image 410
jth41 Avatar asked Feb 28 '26 04:02

jth41


1 Answers

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.

like image 179
Rafał Łużyński Avatar answered Mar 01 '26 17:03

Rafał Łużyński