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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:34:06+00:00 2026-06-09T01:34:06+00:00

I have seen the following code in one of our applications: public class First()

  • 0

I have seen the following code in one of our applications:

public class First()
{
      private Second _second;

      public First()
      {
          _second = new Second(this);
          // Doing some other initialization stuff,
      }

}

public class Second
{
    public Second(First f)
    {
    }
}

In the First() constructor, isn’t it bad that we are sending a reference of class First() before it is fully constructed? I am thinking that the object is only fully constructed once the control logic leaves the constructor.

Or is this okay?

  • 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-09T01:34:07+00:00Added an answer on June 9, 2026 at 1:34 am

    My question is, in the First() constructor, isnt it bad that we are sending a reference of class First() BEFORE it is fully constructed?

    Somewhat. It can be a problem, certainly.

    If the Second constructor just holds onto a reference for later use, that’s not too bad. If, on the other hand, the Second constructor calls back into First:

    public Second(First f)
    {
        f.DoSomethingUsingState();
    }
    

    … and the state hasn’t been set up yet, then that would of course be a Very Bad Thing. If you call a virtual method on First then it could be even worse – you could end up calling into some code which hasn’t even had a chance to run any of its constructor body yet (although its variable initializers will have been executed).

    In particular, readonly fields may be seen first with one value and then later with another…

    I blogged about this a while ago, which may provide some more information.

    Of course, without doing this sort of thing, it’s pretty hard to create two mutually-referential immutable objects…

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

Sidebar

Related Questions

I have following class (as seen through reflector) public class W : IDisposable {
I have seen code with the following logic in a few places: public void
I have seen a web page source code containing the following css declaration at
I have seen the following exception case several times public SomeClass(IEnumerable<T> someValues) { if
I have seen lot projects following this kind of coding style Any significant advantage
I have seen the following links before posting this question http://www.devx.com/wireless/Article/40792/1954 Saving Android Activity
Assume following code, NSString *str=[[NSString alloc] initWithString:@sagar]; [str autorelease]; I have seen many times
I have the following html code: <div id=test> <nav> <ul> <li>One</li> <li>Two</li> </ul> <ul>
I have seen few questions similar to this one, but I wanted to make
I have seen conflicting advice on whether the following code is better def function():

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.