define interface iDataChangeColoring * interface properties nUnchangedColor = rgb( 0, 0, 255 ) && control ForeColor when data has not been changed nChangedColor = rgb( 255, 0, 0 ) && control ForeColor when data has been changed * interface methods public function ChangeColor() * abstract method no code implementation allowed endfunc enddefine define interface i3DFocus * interface methods public function ChangeFocus( plGettingFocus ) * abstract method no code implementation allowed endfunc enddefine define class cTextbox as TextBox implements iDataChangeColoring, i3DFocus public function ChangeColor() * interface method must provide implementation code if ( getfldstate( this.ControlSource ) > 1 ) this.ForeColor = this.nChangedColor else this.ForeColor = this.nUnchangedColor endif endfunc public function ChangeFocus( plGettingFocus ) * interface method must provide implementation code if ( plGettingFocus ) this.SpecialEffect = 0 else this.SpecialEffect = 1 endif function GotFocus() dodefault() this.ChangeFocus( .t. ) endfunc function LostFocus() dodefault() this.ChangeFocus( .f. ) this.ChangeColor() endfunc endfunc define class cCheckbox as Checkbox implements iDataChangeColoring, i3DFocus public function ChangeColor() * interface method must provide implementation code if ( getfldstate( this.ControlSource ) > 1 ) this.ForeColor = this.nChangedColor else this.ForeColor = this.nUnchangedColor endif endfunc public function ChangeFocus( plGettingFocus ) * interface method must provide implementation code * null implementation, we really don't want to change this appearance * of course we could simple not implement this interface, but we * do to provide consistency across controls endfunc enddefineIgnore the replication of code it's only in here as an example.
? thiform.txtFirstName.nChangedColor
if it's an instance or subclass of the cTextbox.define interface iXYZ as iMyCoolInterface && yes interfaces support inheritance public function MethodX * abstract method no code implementation allowed endfunc enddefine define interface iQWERTY public function MethodX * abstract method no code implementation allowed endfunc enddefineit doesn't matter to a class that implements both interfaces, because all they are getting from the interface is the method name. The method is will have code in only one place in the class.