Constructors
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Constructors

  1. #1
    Join Date
    Mar 2014
    Posts
    17

    Exclamation Constructors

    Constructors are used to assign the default values to the variables so can't we use the mutator function for doing the same ?

  2. #2
    Join Date
    Jul 2013
    Posts
    288

    Re: Constructors

    Quote Originally Posted by Harris1995 View Post
    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.

  3. #3
    Join Date
    Mar 2014
    Posts
    17

    Re: Constructors

    Quote Originally Posted by razzle View Post
    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

  4. #4
    Join Date
    Jul 2013
    Posts
    288

    Re: Constructors

    Quote Originally Posted by Harris1995 View Post
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center