[Newbies] Are setters a good idea?
Marcin Tustin
mm3 at zepler.net
Sat Sep 27 19:05:40 UTC 2008
The short answer is that you are exposing the internals of the object. If
you have an object that is just a packet of values, great. If you have an
object that will always have e.g. a colour, then possibly great, or possibly
not depending on the domain.
On Sat, Sep 27, 2008 at 7:40 PM, Andy Burnett <
andy.burnett at knowinnovation.com> wrote:
> I read somewhere - can't remember where - that setters are considered evil.
> The argument was that in the real world you can't suddenly change the colour
> of a car, just by settings its colour value. Instead, you have to perform
> some action, e.g. sprayPaintCar: aColour. Therefore in the OO world, one
> should tackle problems in the same way, i.e. if you want to change the value
> of an instance variable, you have to call some sort of action method, that
> makes sense in the context of the object.
>
> Without wishing to send startHolyWar to BeginnersList, do any of the
> experienced developers work this way, or is it just a theoretical position?
>
> cheers
> AB
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20080927/0bf452ae/attachment.htm
More information about the Beginners
mailing list