Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Where to place dodefault()
Message
From
16/11/2018 15:14:10
Al Doman (Online)
M3 Enterprises Inc.
North Vancouver, British Columbia, Canada
 
 
To
16/11/2018 12:40:27
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
01663345
Message ID:
01663475
Views:
45
>>>
>>>*-- Init method of child form
>>>dodefault()  && call the code in the parent INIT method
>>>*-- put the code specific to the child form INIT method
>>>
>>>
>>>Does the above make sense or there is/are issue(s)?
>>
>>Yes, that's the right idea. Some comments:
>>
>>1. You're avoiding the rookie/too little coffee mistake of forgetting to call DODEFAULT() at all, when you actually need the parent class code ;)
>>
>>2. If your method takes parameters, remember to pass them in DODEFAULT()
>>
>>3. Exactly where you place DODEFAULT() depends entirely on your code requirements. In some frameworks you see code like this:
>>
>>
>>* Child form .Init()
>>
>>LPARAMETERS tuParm1, tuParm2, ...
>>
>>=This.BeforeInit( tuParm1, tuParm2, ... )
>>
>>=DODEFAULT( tuParm1, tuParm2, ... )
>>
>>=This.AfterInit( tuParm1, tuParm2, ... )
>>
>>This gives a place to put code you'd like to run before or after a given method's default code, without having to override parent code or worry about exactly where to place DODEFAULT().
>
>Basic template/hook pattern is one of the easiest and (IMO) sadly underused patterns.
>But if you encode it like your example, it can create warts as well.
>The template pattern has to be coded in the uppermost class / best right where it is defined.

Agreed that it's best practice, and frameworks usually do this.

>Each method overriding the pure method HAS to call dodefault first, otherwise all code(s) in before-hook might be not be called before some lines of actual method ;-)

Not sure what you mean here - can you give a more detailed example?

There are some differences between event and method processing, ISTR needing to use some strategic NODEFAULT in some cases to make the former work the way I wanted. But AFAIR regular non-event method code works fine per the pseudo-code I wrote above.

>
>For that reason I prefer as standard template
>xxxAction_Before()
>xxxAction_Execute()
>xxxAction_Finish()
>
>so that each template step can be overridden with dodefault put where it fits best.
>Still, it is best to agree on "normal practices" for before ban finish hook to have "expected" behaviour, be defining default/standard dodefault() locations for those particular methods, so you can expect outer>>inner or inner>>outer call sequence as "normal"
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Reply
Map
View

Click here to load this message in the networking platform