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

  • Home
  • SEARCH
  • 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 812679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:14:24+00:00 2026-05-15T01:14:24+00:00

// stupid title, but I could not think anything smarter I have a code

  • 0

// stupid title, but I could not think anything smarter

I have a code (see below, sorry for long code but it’s very-very simple):

namespace Option1
{
    class AuxClass1
    {
        string _field1;
        public string Field1
        {
            get
            {
                return _field1;
            }
            set
            {
                _field1 = value;
            }
        }

        // another fields. maybe many fields maybe several properties

        public void Method1()
        {
            // some action
        }

        public void Method2()
        {
            // some action 2
        }
    }

    class MainClass
    {
        AuxClass1 _auxClass;
        public AuxClass1 AuxClass
        {
            get
            {
                return _auxClass;
            }
            set
            {
                _auxClass = value;
            }
        }

        public MainClass()
        {
            _auxClass = new AuxClass1();
        }
    }
}

namespace Option2
{
    class AuxClass1
    {
        string _field1;
        public string Field1
        {
            get
            {
                return _field1;
            }
            set
            {
                _field1 = value;
            }
        }

        // another fields. maybe many fields maybe several properties

        public void Method1()
        {
            // some action
        }

        public void Method2()
        {
            // some action 2
        }
    }

    class MainClass
    {
        AuxClass1 _auxClass;

        public string Field1
        {
            get
            {
                return _auxClass.Field1;
            }
            set
            {
                _auxClass.Field1 = value;
            }
        }

        public void Method1()
        {
            _auxClass.Method1();
        }

        public void Method2()
        {
            _auxClass.Method2();
        }

        public MainClass()
        {
            _auxClass = new AuxClass1();
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        // Option1
        Option1.MainClass mainClass1 = new Option1.MainClass();
        mainClass1.AuxClass.Field1 = "string1";
        mainClass1.AuxClass.Method1();
        mainClass1.AuxClass.Method2();

        // Option2
        Option2.MainClass mainClass2 = new Option2.MainClass();
        mainClass2.Field1 = "string2";
        mainClass2.Method1();
        mainClass2.Method2();

        Console.ReadKey();
    }
}

What option (option1 or option2) do you prefer ? In which cases should I use option1 or option2 ? Is there any special name for option1 or option2 (composition, aggregation) ?

  • 1 1 Answer
  • 1 View
  • 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-15T01:14:25+00:00Added an answer on May 15, 2026 at 1:14 am

    According to Law of Demeter, Option2. That way you can freely change the implementation of MainClass, You don’t have to worry about calling code relying on details of AuxClass1, and indeed can remove it entirely if needed.

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

Sidebar

Related Questions

from title it appears a stupid question :) i know but i have a
Sorry for the bad title, but I couldn't think of a better one. I'm
This maybe a stupid question, but as I can not easily undo my change
This probably sounds really stupid but I have noo idea how to implement jquery's
This sounds really stupid, but I was told that you could drag-and-drop visual components
Sorry about the question title, but I couldn't find a more appropriate way to
This might be a stupid question but if there's a better or proper way
It may sound stupid, but sometimes I run into version conflicts between two versions
I'm possibly just stupid, but I'm trying to find a user in Active Directory
This might be a stupid question but I just wanted to make sure... If

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.