Any reason why preference for mutator using void

invisible.hippo

Arch-Supremacy Member
Joined
Nov 8, 2008
Messages
17,902
Reaction score
315
something like

Code:
void setstring1(string);

I have an assignment state to use in this form. However i have no idea why does it need to be like(in terms of benefits)

Thank you
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
something like

Code:
void setstring1(string);

I have an assignment state to use in this form. However i have no idea why does it need to be like(in terms of benefits)

Thank you

You are setting value into an entity, do you have a need to return value from the operator ? Most assignment do not need to return anything.

However, there are some encapsulation design that return the object while you are building the contents so that you can daisy chain, like this

List mylist = new List();

mylist.add(obj1).add(obj2);

There are also some cases where setting something can return the same type as the arguments to indicate spill over or conflict.

For eg:

Set myset = new Set();
oldvalue = myset.put(key, newvalue);

depending on whether there is a conflict where the oldvalue may be NON-NULL

There are also cases, where it return a true/false value to indicate success of the operation.

There is no definite approach to this, it goes with the intended need.
 

invisible.hippo

Arch-Supremacy Member
Joined
Nov 8, 2008
Messages
17,902
Reaction score
315
You are setting value into an entity, do you have a need to return value from the operator ? Most assignment do not need to return anything.
No need

However, there are some encapsulation design that return the object while you are building the contents so that you can daisy chain, like this

List mylist = new List();

mylist.add(obj1).add(obj2);
No i dont need to daisy chain

There are also some cases where setting something can return the same type as the arguments to indicate spill over or conflict.

For eg:

Set myset = new Set();
oldvalue = myset.put(key, newvalue);

depending on whether there is a conflict where the oldvalue may be NON-NULL
Do you mind simplify your explaination, i dont get it.

There are also cases, where it return a true/false value to indicate success of the operation.
Do you mind simplify your explaination, i dont get it.
There is no definite approach to this, it goes with the intended need.
Reply you, thanks
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
Reply you, thanks

Go figure it out.

You want to be more appreciative in your response and learn to have a dialogue that shows you are learning and thinking, not you know or you don't know.

I don't get why I should feed you further. You will want to tell me know what do you not understand.

Response you too. Thanks
 
Last edited:
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top