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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:46:17+00:00 2026-06-19T03:46:17+00:00

I am beginner in object oriented programming and I have one simple question. What

  • 0

I am beginner in object oriented programming and I have one simple question. What is difference between:

public class Calculation
{
     private _externalObject = new ExternalClass();

     public int FirstParameter {get;set;}
     public int SecondParameter {get;set;}
     public int ThirdParameter {get;set;}
     public int FourthParameter 
     {
          get
          {
               _externalObject.Calculate(FirstParameter, SecondParameter, ThirdParameter);
          }
     }
} 

and

public class Calculation
{

     private _externalObject;

     public Calculation()
     {
           _externalObject = new ExternalClass();
     }

     public int FirstParameter {get;set;}
     public int SecondParameter {get;set;}
     public int ThirdParameter {get;set;}
     public int FourthParameter 
     {
          get
          {
               _externalObject.Calculate(FirstParameter, SecondParameter, ThirdParameter);
          }
     }
} 

I want to learn how should I write optimal code.

  • 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-19T03:46:18+00:00Added an answer on June 19, 2026 at 3:46 am

    In this particular case, there isn’t any measurable difference.

    If, however, you had more than one constructor, you would have to initialize the field in each constructor if you didn’t do it directly in the field declaration.

    It is more a matter of personal style than anything.


    Note on class design and integration – if you have an external dependency like that, good OOP would require you to use DI (Dependency Injection) instead of instantiating the value within the class directly. Constructor injection is a good choice:

     private ExternalClass _externalObject;
    
     public Calculation(ExternalClass externalClass)
     {
           _externalObject = externalClass;
     }
    

    The above allows for modification of behaviour without changing the actual class and makes the class more testable.

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

Sidebar

Related Questions

I'm definitely beginner in PDO and object-oriented programming at all. class mysql { public
Beginner question. How come I can do this: Public Class Form1 Private StudentsInMyRoom As
I am an object-oriented programming enthusiast at a beginner level. I have encountered the
A python/django beginner's question: I have a datetime object (drive_date), a time object (start_time)
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
I have a beginner question using pointers in delphi. I create an object and
Beginner here. I have a class with a SoundPool object in it. I would
Level: Beginner I'm doing my first steps in Object Oriented programming. The code is
I'm beginner to programming. This is my code: private void timer1_Tick(object sender, EventArgs e)
I am a Scala beginner and coming from Object Oriented Paradigm. While understanding Functional

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.