note
mvc
<p>
Do you define "predicate function" here as "method that returns a boolean value"? If so, then it reveals something about the object state- information that should be encapsulated.
</p>
<p>
What if you decide that <i>"you can always send!"</i>. Then you have to remove the conditionals from all clients of your object. Or what if there are now 3 states for sending, each requiring a different send method? We want the clients to know as little as possible about the object. Knowing only one method, is better than knowing a method, its return type, and another method.
</p>
<pre>
"...The key question is: How much of one module must be
known in order to understand another module?..."
</pre>
<p>
<i>Yourdon, Ed and Larry L. Constantine. Structured Design: Fundamentals of a Discipline of Computer Program and Systems Design. (1979) On Coupling, p.85</i>
</p>
<p>
Breaking encapsulation here increases coupling between the clients of the object and the object itself. Note I am <i>not</i> saying: never use boolean methods. There may be other design forces besides <i>"encapsulate hermetically"</i>, so we do not know which solution is best here.
</p>
<p>
Code like: "if an object can do this, tell it to do it" <a href="http://www.c2.com/cgi/wiki?CodeSmell"><i>smells</i></a>.
</p>
259306
259971