-
March 20th, 2014, 09:30 AM
#1
Constructors
Constructors are used to assign the default values to the variables so can't we use the mutator function for doing the same ?
-
March 20th, 2014, 09:55 AM
#2
Re: Constructors
Originally Posted by Harris1995
can't we use the mutator
Not if the object is immutable (cannot be changed after construction).
Avoid mutators (setters), that's a fine design principle.
-
March 20th, 2014, 10:01 AM
#3
Re: Constructors
Originally Posted by razzle
Not if the object is immutable (cannot be changed after construction).
Avoid mutators (setters), that's a fine design principle.
Can You explain in more detail . Thanks
-
March 21st, 2014, 01:05 AM
#4
Re: Constructors
Originally Posted by Harris1995
Can You explain in more detail .
Not this time because your other questions indicate it will be very hard to give a meaningful explanation at your current level of knowledge.
So I limit my reply to the pure technical observation that if an object is immutable using a mutator is no option because there won't be any.
And even if a mutator is available and is used to set a default value the setting must take place within the constructor because otherwise it won't be a default value.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|