Re: Facade



On 2006-05-28 03:52:25 -0500, Bart Wakker <bhawa@xxxxxx> said:

Robert Martin <unclebob@xxxxxxxxxxxxxxxx> writes:

I agree. However consider the fact that languages like Ruby,
Python, and Smalltalk take this principle to the maximum extreme.
All methods are segregated. No user of a particular method need
know about any other method of the class.

Could you explain, e.g. for ruby I don't understand what you mean with
"all methods are segregated". Like in any OO language I know, you have
public, private and protected methods.

In languages like Java, you have to know the name of the type in order to call a method. For example, in order to call 'add' you must know you are calling 'add' on a Map. This is just basic static type safety. It also leads to the problem that the ISP tries to resolve. For if you know about Map, you know about ALL the methods declared within Map. And if the signature of one of those methods changes, modules that know about Map will have to be recompiled, even of they don't call that method. (This is worse in C++ than in Java, but is still significant in Java)

In languages like Ruby you call methods on objects without knowning anything at all about their type. When you call 'add' on an object the compiler has no information at all that the object you are calling 'add' on actually has an 'add' method. Thus there is no static type safety. If the object does not accept the 'add' method, there will be a run-time error. So type safety has been relegated to runtime instead of compile time. On the other hand, if the signature of a method of Map changes, only those modules that actually call that method must be recompiled. All other users of Map remain blissfully unaware. Thus in Ruby, Python, Smalltalk, and other dynamically typed language, all interfaces (methods) are maximally segregated. The only way to achieve the same level of segregation in Java would be to put every method into it's own interface and multiply inherit them all into the class that implements them.

--
Robert C. Martin (Uncle Bob)  | email: unclebob@xxxxxxxxxxxxxxxx
Object Mentor Inc.            | blog:  www.butunclebob.com
The Agile Transition Experts  | web:   www.objectmentor.com
800-338-6716                  |



.