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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:02:06+00:00 2026-05-23T11:02:06+00:00

I have a habit of creating classes that tend to pass objects around to

  • 0

I have a habit of creating classes that tend to pass objects around to perform operations on them rather than assigning them to a member variable and having operations refer to the member variable. It feels much more procedural to me than OO.

Is this a terrible practice? If so, what are the adverse effects (performance, memory consumption, more error-prone)? Is it simply easier and more closely aligned to OO principles like encapsulation to favour member variables?

A contrived example of what I mean is below. I tend to do the following;

public class MyObj()
{

  public MyObj() {}

  public void DoVariousThings(OtherObj oo)
  {
    if (Validate(oo))
    {
       Save(oo);
    }
  }

  private bool Validate(OtherObj oo)
  {
    // Do stuff related to validation
  }

  private bool Save(OtherObj oo)
  {
     // Do stuff related to saving
  }

}

whereas I suspect I should be doing the following;

public class MyObj()
{

  private OtherObj _oo;

  public MyObj(OtherObj oo) 
  {
    _oo = oo;
  }

  public void DoVariousThings()
  {
    if (Validate())
    {
       Save();
    }
  }

  private bool Validate()
  {
    // Do stuff related to validation with _oo
  }

  private bool Save()
  {
     // Do stuff related to saving with _oo
  }
}
  • 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-23T11:02:06+00:00Added an answer on May 23, 2026 at 11:02 am

    I think you already answered your question yourself, you seem to be aware of the fact that the 2nd approach is more favorable in general and should be used (unless there are serious reasons for the first approach).

    Advantages that come to my mind immediately:

    • Simplified readability and maintainability, both for you and for others
    • Only one entry point, therefore only needing to checking for != null etc.
    • In case you want to put that class under test, it’s way easier, i.e., getting something like this (extracting interface IOtherObj from OtherObj and working with that):

      public MyObj (IOtherObj oo)  
      {
          if (oo == null) throw...
          _oo = oo;
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My writers have a bad habit of creating empty paragraphs. (I.e., paragraphs that have
I'm working with some developers who have a habit of: perform edits on their
I have this habit always a C++ project is compiled and the release is
I have a habit of hardcoding URLs into my HTML: ...<a href=www.mySite.com/login>logon to your
Some of the developers on the project I work on have a habit of
Coming from C/C++ a long time ago I still have a habit of ensuring
Problem Overview: My application has an enrollment form. Users have a habit of entering
I have acquired the habit of declaring reused variables outside loops from having worked
I have this horrible habit of typing the below and not catching it until
I've got the design habit to have a SqlConnection object populated by a child

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.