Re: Kinds of methods




"Daniel T." <postmaster@xxxxxxxxxxxxx> wrote in message news:postmaster-6FCD75.09250822032006@xxxxxxxxxxxxxxxxxxxxxxxxxx
I just wrote this up for someone on one of the C++ newsgroups. Any
comments?

Member-functions can be categorized into one of 4 types:

modifier - a member-function that can change the external state of the
object. IE calling a modifier could cause one or more other
member-functions of the object's class to behave differently or
produce different output when called on this object, than they
otherwise would before the modifier was called.

producer - a member-function that creates an object for the caller to
use, or sets the state of an object the caller passed in.

accessor - a member-function that gives the caller a pointer/reference
to one of the object's member-variables such that modifying the value
contained in the pointer/reference will change the state of the
object as if a modifier was called.

provider - a member-function that gives to the caller a
pointer/reference to one of the object's member-variables such that
modifying the value contained in the pointer/reference will not
change the state of the object that the member-function was called on.

If it were up to me, I'd split "producers" which create new objects from those which mutate objects passed in. Then, I'd merge the producer which creates new objects with the provider which returns objects.

I'd probably end up with something like:

Setter
Getter
Factory
Mutator

But then there are functions which just return a value based on its inputs, without setting, getting, making, or mutating anything. E.g.

number function double(number n) {
return n * 2;
}

And then there are functions which produce side-effects in the system, without affecting the objects themselves. E.g.

console.write("Hello World!");

I guess you could argue that this write() method is affecting the state of the conceptual console (of which the console object is acting as a proxy for), but then you'd have these "black hole setters", where you're setting some state which you can never actually retrieve again.

- Oliver

.



Relevant Pages

  • Re: Kinds of methods
    ... modifier - a member-function that can change the external state of the ... IE calling a modifier could cause one or more other ... or sets the state of an object the caller passed in. ... accessor - a member-function that gives the caller a pointer/reference ...
    (comp.object)
  • Kinds of methods
    ... modifier - a member-function that can change the external state of the ... IE calling a modifier could cause one or more other ... or sets the state of an object the caller passed in. ... accessor - a member-function that gives the caller a pointer/reference ...
    (comp.object)
  • Re: Kinds of methods
    ... IE calling a modifier could cause one or more other member-functions of the object's class to behave differently or produce different output when called on this object, than they otherwise would before the modifier was called. ... producer - a member-function that creates an object for the caller to use, or sets the state of an object the caller passed in. ... Read Accessor: basically a synchronous getter for knowledge responsibilities. ... basically a synchronous setter for knowledge responsibilities. ...
    (comp.object)
  • Re: Kinds of methods
    ... a modifier since it never returns to the caller but does change the external ... modifier - a member-function that can change the external state of the ... accessor - a member-function that gives the caller a pointer/reference ...
    (comp.object)
  • Re: Kinds of methods
    ... modifier - a member-function that can change the external state of the ... IE calling a modifier could cause one or more other ... Destructor is different in the way of its composition. ... Constructor has an output parameter of the object's ...
    (comp.object)