Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 857665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:25:59+00:00 2026-05-15T08:25:59+00:00

UPDATE : My original question wasn’t quite clear. I’m looking for the name of

  • 0

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;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:26:00+00:00Added an answer on May 15, 2026 at 8:26 am

    Principles that may apply to this example are:

    Information Hiding: Segregate design details in your code that are likely to change. Create a stable interface that protects the rest of the program from the implementation.

    Encapsulation: Compartmentalize the elements of an abstraction that constitute its structure and behavior. Separate the contractual interface of an abstraction from its implementation. Use standard language mechanisms to bundle the data with the interface.

    Note that the definitions of Information Hiding and Encapsulation I’ve given are quite similar, and various people have their own definitions of what these mean. I’ve pulled these from Wikipedia.

    Interface Segregation Principle: The dependency of one class to another should depend on the smallest possible interface.

    The question you must determine is whether writing your class this way, where Child itself is part of the interface, is a stable and minimal interface for clients to depend on. In most cases, OO programmers prefer to rely on an explicit set of methods as their interface instead of data members, so that they can change out the data members at will. Some will recommend that technique as a dictum. It may or may not apply in your case.

    There’s another principle that may or may not apply to your example:

    Law of Demeter: Only talk to your immediate friends.

    The Law of Demeter discourages deep access hierarchies like p.Child.Child.Child. Why? Because clients are then assuming deep structural knowledge about the objects they are talking to, and it increases coupling between the client and those objects. Having said this, I think there are plenty of examples in the world where this coupling is acceptable; you’d need to decide whether it applies in your case as well.

    EDIT: With your revised example, the Law of Demeter looks to me much closer to what you’re looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update is below code chunks. Original Question: I have an input field that is
Update 7/17 SOLVED I've updated my code to the Solved version. Original Question I'm
ORIGINAL (see UPDATED QUESTION below) I am designing a new laboratory database that tests
UPDATE: Perhaps this wasn't clear from my original post, but I'm mainly interested in
UPDATE: This question is out of date, but left for informational purposes. Original Question
UPDATE: I should have mentioned in the original post that I want to learn
UPDATE: I've been playing around with this more, and it seems like tmux's clear-history
Edit: I'm rewriting this question because I apparently wasn't clear. Sometimes the GPS service
Original Question Consider the following scenario: public abstract class Foo { public string Name
Here is my current question: I'm guessing that my problem (described below) is being

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.