- 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()
andsetNext()
) 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
. TheNode
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.