UPDATE: My original question wasn't quite clear. I'm looking for the name of the principle that code like the example below violates.
(I've updated the code example to better resemble the scenario I'm talking about. The original code example I included can be found at the bottom. This was a poorly chosen example because it illustrated a hierarchical structure that actually should provide access to sub-members at an arbitrary "depth" level and furthermore had almost nothing to do with composition, which is what I meant to be asking about.)
I'm pretty sure there's a term for this and I'm just having trouble thinking of it.
Example of bad code:
public interface IJumper
{
void Jump();
}
public class Creature
{
public IJumper Jumper;
}
var c = new Creature();
c.Jumper.Jump();
Example of better code:
public class Creature : IJumper
{
private IJumper _jumper;
public void Jump()
{
_jumper.Jump();
}
}
var c = new Creature();
c.Jump();
I'm pretty sure I've heard this (exposing a member object directly so that all its properties/methods are publicly accessible) described as a bad thing due to [insert name of principle here]. What is the word I'm looking for?
(Note that I'm not asking why this is/isn't a bad thing; I'm just looking for the term, which for the life of me I can't remember.)
Original (bad) code example:
public class Person
{
public Person Child;
// ...
}
Person p = new Person("Philip J. Fry");
// what is the term for this?
Person greatGrandchild = p.Child.Child.Child;