On Mar 22, 2007 4:15 PM, Arnaud Nicolet wrote: > May I ask you for a simple example where interface is the only way to > solve a problem?
There are often many ways to solve a problem but in some circumstances using interfaces is really the best and very usefull. Here's one example. I have a window where user changes some default values that several parts of the software (controls and floating windows) needs to know about the changes when they occur. Using an interface was the easy way. All controls that needs to know when the changes occured implemented the interface and when a change is made I just use the interface to tell all controls that they need to update the default values. If I need to add other controls in future that needs to know about the changes I just implement the interface and "viola". If I was not using an interface I would have to code a lot more to achieve this. Other example: I had a problem once with some custom controls on a window that needed to know when a resized event occured on the window in order to do some stuff. This would be easy if I had just one or two. But with several this would require some more work everytime I wanted to add or remove a control. By using an interface, when the window resizes, all controls that implements the interface are automatically notified. Sure there are other ways to do this (and maybe even better) but to me it seemed, at that time, the best approach to solve the problem. Carlos _______________________________________________ Unsubscribe or switch delivery mode: <http://www.realsoftware.com/support/listmanager/> Search the archives: <http://support.realsoftware.com/listarchives/lists.html>
