Re: Kinds of methods
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Wed, 22 Mar 2006 17:04:04 GMT
"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
.
- Follow-Ups:
- Re: Kinds of methods
- From: Daniel T.
- Re: Kinds of methods
- References:
- Kinds of methods
- From: Daniel T.
- Kinds of methods
- Prev by Date: Re: UML-ish question
- Next by Date: Re: UML-ish question
- Previous by thread: Kinds of methods
- Next by thread: Re: Kinds of methods
- Index(es):
Relevant Pages
|