[Tutor] Question about 'Predicate Methods'

ahimsa ahimsa@onetel.net.uk
Tue Mar 25 09:03:08 2003


This was useful to me Alan, thank you.

On Tuesday 25 Mar 2003 1:59 pm, alan.gauld@bt.com wrote:
> > > Predicate methods(or even predicate functions!) are really methods
> > > which answer a question, they usually return a boolean result.
>
> ...
>
> > > Examples in a graphics library would include methods like:
>
> ....
>
> > and the method can only return a 1 or a 0 (true or a false):
>
> Strictly spreaking a predicate should be boolean however some texts
> allow things like count values to be classified as predicates.
>
> Thus a method like sides() might return 3,4,.... depending on
> how many sides the shape had. Is that an accessor or a predicate?
> Technically it's an accessor (even though the number of sides might
> not really exist as an attribute!), but some folks might call it
> a predicate because it answers a question...
>
> > Could you give a brief eg of an accessor method returning an
> > attribute value?
>
> See the example above. The usual names are things like
>
> getSides()
>
> [ But I personally hate that style of naming as it implies a breakdown
> in the data hiding of the class. I just want the object to tell me
> how many sides, I don;t carte if its an internal stored bvalue or
> not... ]
>
> > Would this be like an output of a calculation perhaps?
>
> Yes as discussed above. But the real point is that in any OOP solution
> the user should neither know nor care whether its calculated or not.
>
> > And the description is based on the attributes of the method being
> > 'read-only', and dichotomous?
>
> Just so.
>
> Alan g.
> Author of the Learn to Program website
> http://www.freenetpages.co.uk/hp/alan.gauld/

--=20
News from a diiferent perspective:
http://www.scoop.co.nz
http://www.fromthewilderness.com
____________________________
Prevent digital monopoly:
http://www.againsttcpa.com