tag:blogger.com,1999:blog-381129527146258002.post7135619505302264491..comments2024-03-28T04:51:40.042-07:00Comments on Agile Otter Blog: Full Test Access With Data Hiding for ProductionAgileotterhttp://www.blogger.com/profile/10773578598860454277noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-381129527146258002.post-68807111667075648212010-03-22T11:19:34.943-07:002010-03-22T11:19:34.943-07:00I'm largely in agreement with you, Tim, but th...I'm largely in agreement with you, Tim, but there is (at least) one down side with interfaces (the Java type, that is) and that is they can't be changed after they have been published. You can't even add a new method, or remove something that isn't being used. Unless, that is, you control all the implementations of the interface as well.<br /><br />My approach of late, in Java, is to use interfaces when I can distill the concept down to 1-3 methods. Anything bigger and I probably haven't got the real essence of what the thing is, so it's probably going to evolve, and in that case, I'll use a public class as the interface. (I might still make the public class abstract, and keep the concrete implementations behind a factory interface, so I could still define public non-interface methods in those subclasses and it amounts to the same thing.)Michael Hackettnoreply@blogger.comtag:blogger.com,1999:blog-381129527146258002.post-86723187900251483542010-03-21T19:01:49.694-07:002010-03-21T19:01:49.694-07:00By "interface" I'm talking of declar...By "interface" I'm talking of declared interfaces, which are approximated in C++ as pure virtual base classes or abstract base classes. In java and c# they're called "interfaces" instead.<br /><br />If so by "programming to interfaces" I mean that you always pass, receive, return, manipulate classes through interfaces (unless it is beyond absurd to do so, as with integers). <br /><br />In that case, the published set of methods in the base class are the only methods the world knows, other than the implementation class itself and possibly the factory or factory method that makes it.<br /><br />So if I take an interface that has three methods, and the class implementing it has twelve, I can only see the three. To see more I would have to "pierce the veil" by down-casting from the interface to the concrete class, which is generally a poor idea. Since everyone knows the interface, not the implementation, then data and inherited methods in the implementer are unreachable.<br /><br />In cases where a class is protected by an interface, the data and utility methods can be public if you like, because "public" loses its meaning.<br /><br />That's the point: the tests are written to the implementation, and get full disclosure, while the classes who use the interface have a limited view.Agileotterhttps://www.blogger.com/profile/10773578598860454277noreply@blogger.comtag:blogger.com,1999:blog-381129527146258002.post-73846882352887803392010-03-21T11:10:02.106-07:002010-03-21T11:10:02.106-07:00"If we program through interfaces..."
Wh..."If we program through interfaces..."<br />What do you mean by the term interface? Is an interface the full body of public methods available to a class? If you have no private variables or methods, how do you store the class data, or encapsulate functions that need to be reused by various public methods of the class?Walter Moorenoreply@blogger.com