Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Which is the right place for the code?
Message
De
17/11/2003 17:13:40
 
 
À
17/11/2003 17:04:58
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Divers
Thread ID:
00850779
Message ID:
00850784
Vues:
15
This message has been marked as a message which has helped to the initial question of the thread.
>I have the following doubt: which is the right place for the code?
>For example, if I have a form with three Command Buttons on it:
>btnAccept, btnCancel and btnDo, must the Click() event of each button have the code, or each one must do calls to forms methods, i.e.: ThisForm.Accept(), or ThisForm.Cancel(), etc.?
>I think the later is the right one, considering that the buttons are the User tier, and the form is the Business one, and everyone who wants to call those methods (a toolbar, for example), calls oRefToMyform.Do().
>But a teammate of mine says that all the code must reside in the class that do the job, and for him the button is who really does it, and a client who wants to use the services of this class, must call oRefToMyform.btnDo.Click().


The second case is right. Buttons should send messages to the objects (methods) that know what to do with the information.
If btnAccept knows too much about what Accept means, then it is not reusable. You cannot drop it into a new form as its code would not fit the situation. OTOH the container (in this case most likely a form), should know what Accept() means in that particular, (concrete) instance, and can act accordingly.

See:
http://fox.wikis.com/wc.dll?Wiki~EventsShouldAlwaysCallMethods
http://fox.wikis.com/wc.dll?Wiki~ClassAndObjectHeuristics


Alex Feldstein, MCP, Microsoft MVP
VFP Tips: English - Spanish
Website - Blog - Photo Gallery


"Once again, we come to the Holiday Season, a deeply religious time that each of us observes, in his own way, by going to the mall of his choice." -- Dave Barry
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform