Skip to main content
added 3 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237
  • getters and setters.

    getters and setters

    The point of declaring an element private is to restrict an access to it. Providing an unchecked getter and setter (as getNext() and setNext()) defeats this purpose. You may as well make _next public.

    The real goal of restricting access is to help the client to not mess things up (a scientific term is maintaining an invariant). I don't see what invariant is maintained by _value. The Node class doesn't really care what value the node stores; it is the client code that does. A _value getter just complicates client's life.

The point of declaring an element private is to restrict an access to it. Providing an unchecked getter and setter (as getNext() and setNext()) defeats this purpose. You may as well make _next public.

The real goal of restricting access is to help the client to not mess things up (a scientific term is maintaining an invariant). I don't see what invariant is maintained by _value. The Node class doesn't really care what value the node stores; it is the client code that does. A _value getter just complicates client's life.

  • Sorely missed are iterators. Their absence locks your class out of the STL algorithms library. A client would have to reimplement everything that STL provides for free.

    Sorely missed are iterators. Their absence locks your class out of the STL algorithms library. A client would have to reimplement everything that STL provides for free.

  • getters and setters.

The point of declaring an element private is to restrict an access to it. Providing an unchecked getter and setter (as getNext() and setNext()) defeats this purpose. You may as well make _next public.

The real goal of restricting access is to help the client to not mess things up (a scientific term is maintaining an invariant). I don't see what invariant is maintained by _value. The Node class doesn't really care what value the node stores; it is the client code that does. A _value getter just complicates client's life.

  • Sorely missed are iterators. Their absence locks your class out of the STL algorithms library. A client would have to reimplement everything that STL provides for free.
  • getters and setters

    The point of declaring an element private is to restrict an access to it. Providing an unchecked getter and setter (as getNext() and setNext()) defeats this purpose. You may as well make _next public.

    The real goal of restricting access is to help the client to not mess things up (a scientific term is maintaining an invariant). I don't see what invariant is maintained by _value. The Node class doesn't really care what value the node stores; it is the client code that does. A _value getter just complicates client's life.

  • Sorely missed are iterators. Their absence locks your class out of the STL algorithms library. A client would have to reimplement everything that STL provides for free.

Source Link
vnp
  • 57.3k
  • 4
  • 51
  • 140

  • getters and setters.

The point of declaring an element private is to restrict an access to it. Providing an unchecked getter and setter (as getNext() and setNext()) defeats this purpose. You may as well make _next public.

The real goal of restricting access is to help the client to not mess things up (a scientific term is maintaining an invariant). I don't see what invariant is maintained by _value. The Node class doesn't really care what value the node stores; it is the client code that does. A _value getter just complicates client's life.

  • Sorely missed are iterators. Their absence locks your class out of the STL algorithms library. A client would have to reimplement everything that STL provides for free.