in Coldmud discussion meeting
daemon@ATHENA.MIT.EDU (Sat Apr 9 11:43:38 1994
To: firstname.lastname@example.org (Ray Nawara jr.)
In-Reply-To: Your message of "Thu, 31 Mar 1994 10:26:47 PST."
Date: Sat, 09 Apr 1994 10:38:21 -0500
From: Erik Ostrom <email@example.com>
> the reason I wanted to have an accessor was for abstraction purposes..
> having only one method that directly set a parameter, with all other
> methods calling the accessor to change or read the value, so that
> changes could be made to how that parameter was set (or returned)
One thing to consider is that sometimes you want the setter called
internally to be different from the setter called by outside methods.
For example, suppose you have a list parameter and you want other
objects to be able to add or remove elements, or just set it directly.
But you also want to make sure the elements are all of type symbol.
.set_mylist(thelist) checks the type of every element of thelist
Now, .add_mylist takes one argument and has to check that it's of type
symbol. But if it calls .set_mylist, every element already in the
list--which you _know_ is all symbols--gets rechecked. And
.del_mylist is even worse. When .add_mylist calls .set_mylist, at
least there's some purpose in checking the new value. When
.del_mylist calls .set_mylist, there's no point to it at all.
So, what you want may be a ._set_mylist, or .internal_set_mylist, or
something, which doesn't do any type checking. This also makes the
permissions checking a little less tricky; the internal setter just
checks that it's being called by a method on the same object, and the
external setter (along with the adder and deleter) checks permissions
by owner or permitted-objects or whatever.
No, I don't know why I'm rambling about this.