dbTalk Databases Forums  

Duplicating Code

comp.databases.xbase.fox comp.databases.xbase.fox


Discuss Duplicating Code in the comp.databases.xbase.fox forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Gene Wirchenko
 
Posts: n/a

Default Duplicating Code - 07-21-2004 , 06:29 PM






I have two pairs of classes that are nearly identical. The
problem is that the differences are where it is awkward. The
differences (apart from comments saying how similar the classes are)
are merely
define class atgettext as textboxbf
vs.
define class atgetedit as textboxbf
and
define class textboxbf as textbox
vs.
define class editboxbf as editbox

Any changes I make to one, I make to the other.

Is there any way to have only one copy of the code?

#include will not work as it specifically ignores VFP statements.
That is too bad, as
define class atgettext as textboxbf
#include "atgetcode.h"
enddefine
define class atgetedit as editboxbf
#include "atgetcode.h"
enddefine
define class textboxbf as textbox
#include "bf.h"
enddefine
define class editboxbf as editbox
#include "bf.h"
enddefine
would have been a very concise solution.

Is there something I am overlooking, or am I stuck with
maintaining two copies of the code?

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.

Reply With Quote
  #2  
Old   
Jacobus Terhorst
 
Posts: n/a

Default Re: Duplicating Code - 07-21-2004 , 07:09 PM






You can create a new class with all the PEM's common to both.

In both classes you refer to that bridge class.

in the init event of both classes you could use AddProperty or AddObject to
use that bridge class:
this.AddObject("oBridge", "CBridge") or
this.AddPropertyt("oBridge",createobject "CBridge"))

in the for example the Valid event of both classes you would use:

return this.oBridge.Valid()


Jacobus Terhorst

"Gene Wirchenko" <genew (AT) mail (DOT) ocis.net> wrote

Quote:
I have two pairs of classes that are nearly identical. The
problem is that the differences are where it is awkward. The
differences (apart from comments saying how similar the classes are)
are merely
define class atgettext as textboxbf
vs.
define class atgetedit as textboxbf
and
define class textboxbf as textbox
vs.
define class editboxbf as editbox

Any changes I make to one, I make to the other.

Is there any way to have only one copy of the code?

#include will not work as it specifically ignores VFP statements.
That is too bad, as
define class atgettext as textboxbf
#include "atgetcode.h"
enddefine
define class atgetedit as editboxbf
#include "atgetcode.h"
enddefine
define class textboxbf as textbox
#include "bf.h"
enddefine
define class editboxbf as editbox
#include "bf.h"
enddefine
would have been a very concise solution.

Is there something I am overlooking, or am I stuck with
maintaining two copies of the code?

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.



Reply With Quote
  #3  
Old   
Thomas Ganss
 
Posts: n/a

Default Re: Duplicating Code - 07-22-2004 , 04:17 AM



Gene,

if you use those classes *not* very often in your app,
I'ld wrap them in a common container.
But if those controls are your most often used GUI elements,
this will lower form speed if you have many GUI controls.

In that case the above mentioned bridge should be used,
but I'ld add a twist: give each control the necessary properties
(duplicating those should be easy) and keep the common code
in as few classes as possible, instatiating them ONCE at the app
level and call the methods with a reference of the calling object.


In the control:
= goApp.oBehaveTextboxbf.ColorMethod(this, lnNewColour)
or
= this.oBridgePointer.ColorMethod(this, lnNewColour)

and in the behaviour object you can set

ColorMethod(this, lnNewColour)
lParameter toCtrl, tnCol
toCtrl.DisabledBackColour = m.tnCol

my 0,02 EUR

thomas
"Gene Wirchenko" <genew (AT) mail (DOT) ocis.net> schrieb im Newsbeitrag
news:0futf0l7i2fdimm2fik8n3q2h60f00vqto (AT) 4ax (DOT) com...
Quote:
I have two pairs of classes that are nearly identical. The
problem is that the differences are where it is awkward. The
differences (apart from comments saying how similar the classes are)
are merely
define class atgettext as textboxbf
vs.
define class atgetedit as textboxbf
and
define class textboxbf as textbox
vs.
define class editboxbf as editbox

Any changes I make to one, I make to the other.

Is there any way to have only one copy of the code?

#include will not work as it specifically ignores VFP statements.
That is too bad, as
define class atgettext as textboxbf
#include "atgetcode.h"
enddefine
define class atgetedit as editboxbf
#include "atgetcode.h"
enddefine
define class textboxbf as textbox
#include "bf.h"
enddefine
define class editboxbf as editbox
#include "bf.h"
enddefine
would have been a very concise solution.

Is there something I am overlooking, or am I stuck with
maintaining two copies of the code?

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.



Reply With Quote
  #4  
Old   
Gene Wirchenko
 
Posts: n/a

Default Re: Duplicating Code - 07-22-2004 , 10:34 AM



"Thomas Ganss" <TGanss_RemoveForRealAdress (AT) T-Online (DOT) de> wrote:

Quote:
if you use those classes *not* very often in your app,
I'ld wrap them in a common container.
I do not understand what you mean here about wrapping *classes*
in a container.

Quote:
But if those controls are your most often used GUI elements,
this will lower form speed if you have many GUI controls.
They are bases of my class hierarchies.

Quote:
In that case the above mentioned bridge should be used,
but I'ld add a twist: give each control the necessary properties
(duplicating those should be easy) and keep the common code
in as few classes as possible, instatiating them ONCE at the app
level and call the methods with a reference of the calling object.


In the control:
= goApp.oBehaveTextboxbf.ColorMethod(this, lnNewColour)
or
= this.oBridgePointer.ColorMethod(this, lnNewColour)

and in the behaviour object you can set

ColorMethod(this, lnNewColour)
lParameter toCtrl, tnCol
toCtrl.DisabledBackColour = m.tnCol
[snipped previous]

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.


Reply With Quote
  #5  
Old   
Thomas Ganss
 
Posts: n/a

Default Re: Duplicating Code - 07-22-2004 , 05:25 PM



Gene,
Quote:
I do not understand what you mean here about wrapping *classes*
in a container.
Just put them in the container. The container container class is common,
branching out with the added controls into different subclasses.

HTH

thomas




Reply With Quote
  #6  
Old   
Gene Wirchenko
 
Posts: n/a

Default Re: Duplicating Code - 07-22-2004 , 07:21 PM



"Thomas Ganss" <TGanss_RemoveForRealAdress (AT) T-Online (DOT) de> wrote:

Quote:
I do not understand what you mean here about wrapping *classes*
in a container.

Just put them in the container. The container container class is common,
branching out with the added controls into different subclasses.

HTH
It does not. It sounds as if you are confusing classes and
objects. Please be more specific.

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.


Reply With Quote
  #7  
Old   
Thomas Ganss
 
Posts: n/a

Default Re: Duplicating Code - 07-24-2004 , 03:49 AM



not tested, but you should get the idea...

Define Class AtGetStr as Container
Function init()
if pemstat(this, oInputCtrl, 5)
= bindevent(oInputCtrl, "GotFocus", this, "GotFocusDelegate")
else
wait wind "Don't instantiate abstact classes"
return .f.
endif
EndFunc
Procedure GotFocusDelegate()
this.oInputCtrl.BackColor = RGB(0,255,0)
EndProc
EndDefine

Define class atgettext as AtGetStr
Add Object oInputCtrl as TextBoxF
EnDefine

Define class atgettext as AtGetEdit
Add Object oInputCtrl as EditBoxF
EnDefine



"Gene Wirchenko" <genew (AT) mail (DOT) ocis.net> schrieb im Newsbeitrag
news:gcm0g0pi3al09b9ei879cboqfgvcb18vgv (AT) 4ax (DOT) com...
Quote:
"Thomas Ganss" <TGanss_RemoveForRealAdress (AT) T-Online (DOT) de> wrote:

I do not understand what you mean here about wrapping *classes*
in a container.

Just put them in the container. The container container class is common,
branching out with the added controls into different subclasses.

HTH

It does not. It sounds as if you are confusing classes and
objects. Please be more specific.

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.



Reply With Quote
  #8  
Old   
Thomas Ganss
 
Posts: n/a

Default Re: Duplicating Code - 07-24-2004 , 04:51 AM



grr, the 3rd should be

Define class AtGetEdit as AtGetStr
Add Object oInputCtrl as EditBoxF
EndDefine

of course...

thomas

"Thomas Ganss" <TGanss_RemoveForRealAdress (AT) T-Online (DOT) de> schrieb im
Newsbeitrag news:cdt7mo$9dd$01$1 (AT) news (DOT) t-online.com...
Quote:
not tested, but you should get the idea...

Define Class AtGetStr as Container
Function init()
if pemstat(this, oInputCtrl, 5)
= bindevent(oInputCtrl, "GotFocus", this, "GotFocusDelegate")
else
wait wind "Don't instantiate abstact classes"
return .f.
endif
EndFunc
Procedure GotFocusDelegate()
this.oInputCtrl.BackColor = RGB(0,255,0)
EndProc
EndDefine

Define class atgettext as AtGetStr
Add Object oInputCtrl as TextBoxF
EnDefine

Define class atgettext as AtGetEdit
Add Object oInputCtrl as EditBoxF
EnDefine



"Gene Wirchenko" <genew (AT) mail (DOT) ocis.net> schrieb im Newsbeitrag
news:gcm0g0pi3al09b9ei879cboqfgvcb18vgv (AT) 4ax (DOT) com...
"Thomas Ganss" <TGanss_RemoveForRealAdress (AT) T-Online (DOT) de> wrote:

I do not understand what you mean here about wrapping *classes*
in a container.

Just put them in the container. The container container class is
common,
branching out with the added controls into different subclasses.

HTH

It does not. It sounds as if you are confusing classes and
objects. Please be more specific.

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.