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 7905139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:21:44+00:00 2026-06-03T10:21:44+00:00

To explain my problem, let me show you the example code with C#. interface

  • 0

To explain my problem, let me show you the example code with C#.

interface IConstructorInfoSelector
{
    //ConstructorInfo is System.Reflection.ConstructorInfo class.
    ConstructorInfo SelectConstructorInfo(Type declaringType);
}

class TestClass
{
    private readonly ConstructorInfo _constructorInfo;

    public TestClass(IConstructorInfoSelector constructorInfoSelector, Type type)
    {
        //Let the line to (A)
        _constructorInfo = constructorInfoSelector.SelectConstructorInfo(type);
    }

    public TestClass(ConstructorInfo constructorInfo)
    {
        _constructorInfo = constructorInfo;
    }

    public Type GetTypeForConstructor()
    {
        //Let the line to (B)
        return _constructorInfo.DeclaringType;
    }
}

On the example, if I construct the TestClass with ctor(IConstructorInfoSelector, Type) and call the GetTypeForConstructor, it will violate the LoD(the law of Demeter principle) through the line (A) and (B).

However, if I execute the following code, does the code violate the LoD? I think that on the one hand, it does not violate because the testClass object at the line (C) is initialized within a method and the GetTypeForConstructor method is called and on the other hand, it seem to violate the principle as the above case. To sum up, if a return object is used to create an other object, this execution will be considered as violation of the LoD?

class LoDQuestionForTestClass
{
    public void DeosThisVoliateTheLoD()
    {
        IConstructorInfoSelector concreteSelector = ...; 
        Type testType = ...;
        var selectConstructorInfo = concreteSelector.SelectConstructorInfo(testType);
       //Let the line to (C)
        var testClass = new TestClass(selectConstructorInfo);
        var result = testClass.GetTypeForConstructor();
    }
}
  • 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-06-03T10:21:48+00:00Added an answer on June 3, 2026 at 10:21 am

    If one object depends on the behavior of another object supplied by a third object you violate LoD. The populistic verion of which is “Don’t trust a friend of a friend”

    In your second example you have another object depending on an object supplied by a third party so yes that does violate “don’t trust a friend of a friend” except if selectConstructorInfois only ever used for it’s value.

    It’s worth to note that LoD was created for a specific project (Demeter) and that it in it’s strictest form might not apply to any other project.

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

Sidebar

Related Questions

The easiest way to explain this problem is to show you some code: Public
Due to my poor English, let me use example to explain my problem. 1,
I have a problem with js menu code. first let me explain what I
It might sound unnecessary, but let me explain my problem first. Probably then it
I'm struggling with add_custom_command. Let me explain the problem in detail. I've these set
I have a problem with Facebook. Let me explain what I'm trying to do.
Let's see if I can explain myself, I have this models: class BillHeader(models.Model): number
Let me explain my problem, and hopefully someone can offer some good advice. I
Let me explain the problem in detail. I have a main git branch on
How would you begin improving on a really bad system? Let me explain what

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.