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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:58:28+00:00 2026-05-20T04:58:28+00:00

In terms of a clean design, which is preferable? 1) Passing an object, say

  • 0

In terms of a clean design, which is preferable?

1) Passing an object, say yourself, to another class method which will manipulate the attributes of the passed object directly.

Inside Class A…

B.doStuff(this);

2) Pass the object’s attributes instead, and either assign the return back to the attributes, or pass by reference.

Inside Class A…

this.var1 = B.doStuff(this.var1);

The downside to the first method is ambiguity, it isn’t explicit what B is altering in A.
The downside to the second method is that unless attributes are passed by reference/pointers, then an array would need to be returned, and would also constitute a longer function call if you end up passing a lot of attributes. I’m guessing the correct choice is dependant on the situation, but are there other advantages/disadvantages anyone else can come up with before I make a decision?

EDIT: Due to the fact that there will be a large amount of attributes passed to the second class (I am delegating certain tasks to it), I think it warrants the use of the first method in this case. Another downside I came up with was that Class B can only access public attributes and methods in Class A, whereas the second method allowed Class B to manipulate private attributes that Class A may not wish to reveal to the public. But once again, using the second method is more common and certainly more preferable in cases where only a few variables will be accessed.

  • 1 1 Answer
  • 4 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-20T04:58:29+00:00Added an answer on May 20, 2026 at 4:58 am

    You should opt for that design which provides least amount of information to the function but optimum enough for the working of the function. This ensures least amount of side effects to expect from the processing.

    I think this question comes down to whether to pass value by reference or by value.

    Mostly the functions are supposed to least to no side effects but if your Intention of function is to process the Data being passed in the arguments then passing the whole class reference is more better.

    For Example when you take a reference to a Graphic objects in a Forms paint event (in C#), it is known that the manipulation will be done on the Object reference passed(But surely it depends upon your requirement and Implementation).

    If your function can work properly without requirement of whole Class reference being passed then you should again opt for that. But remember passing lots of parameters by value are more resource intensive as a new copy is to be created every time and so new Memory is to be allocated, where as in by reference you are just passing a reference so no New memory is being allocated.

    You second design can be used if you want your method to have no side effect on the data passed instead it works on the data provided and creates a new Object that contains the result, which you in turn assign to required attributes.

    Usually the perception of the readers of your code is that, if there is some function being called on the Right side of the assignment operator then he know that something is done with data but a new Data is being returned and hence he generally doesn’t expect it to do manipulation to the data provided as Parameter. If reader only see a function call without any assignment operator then he expect that something is done to the data being provided as Parameter.

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

Sidebar

Related Questions

I'm currently in the process of developing a fairly large static library which will
For my Information Retrieval class I have to make an index of terms from
The design of GHC is based on something called STG, which stands for spineless,
suppose I have an object like this: class Spline { public: Spline(std::size_t const dim);
I am looking for a suggestion for a DB design not in terms of
I'm in the process of creating a web app in PHP which will be
Sometimes I get libraries from different design teams. One uses gcc 3.x and another
In terms of performance and efficiency, is it better to use lots of small
In terms of actual low level atomic instructions and memory fences (I assume they're
In terms of SQL terminology, does HEAP stands for a table that has Non-Clustered

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.