Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Class Inheritance Demo

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Class Inheritance Demo

    Here is a demo showing some aspects of inheritance:

    James

    Code:
    'SED_PBCC
    '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '                      Test of inheritence and Method Overrides (PBCC 5.0)
    '                               James C. Fuller August 2, 2008
    '                                   [email protected]
    '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    'Note the use of both ME and MYBASE.
    'As it was explained to me:
    'Even though they seem to produce the same results ME is for use with the
    'derived Class/Interface methods where MYBASE is for use with the Base Class/Interface
    'Methods.
    'To confuse a bit more(?) ME is also used for access to all base class instance variables
    'from within a derived class.
    '==============================================================================
    CLASS cBase
    	INSTANCE LBase AS LONG,sBase AS STRING
    	INTERFACE iBase : INHERIT IUNKNOWN
    		METHOD mBase( BYVAL a AS LONG)
    			? "mBase a = ";FORMAT$(a)
    		END METHOD
    		PROPERTY GET LBase() AS LONG
    			PROPERTY = LBase
    		END PROPERTY
    		PROPERTY SET LBase(BYVAL Param AS LONG)
    			LBase = Param
    		END PROPERTY
    
    		PROPERTY GET sBase() AS STRING
    			PROPERTY = sBase
    		END PROPERTY
    		PROPERTY SET sBase(BYVAL Param AS STRING)
    			sBase = Param
    		END PROPERTY
    
    		METHOD OrMeth()
    			?"iBase     OrMeth"
    		END METHOD
    	END INTERFACE
    END CLASS
    '------------------------------------------------------------------------------
    CLASS cDrvOne
    	INSTANCE sDrvOne AS STRING
    	INTERFACE iDrvOne : INHERIT cBase,iBase
    		OVERRIDE METHOD OrMeth()
    			?"iDrvOne   OrMeth"
    			MYBASE.OrMeth
    		END METHOD
    		METHOD mDrvOne(BYVAL b AS LONG)
    			?"mDrvOne b = ";FORMAT$(b)
    		END METHOD
    
    		PROPERTY GET sDrvOne() AS STRING
    			PROPERTY = sDrvOne
    		END PROPERTY
    		PROPERTY SET sDrvOne(BYVAL Param AS STRING)
    			sDrvOne = Param
    		END PROPERTY
    	END INTERFACE
    END CLASS
    '------------------------------------------------------------------------------
    CLASS cDrvTwo
    	INSTANCE sDrvTwo AS STRING
    	INTERFACE iDrvTwo : INHERIT cDrvOne,iDrvOne
    		OVERRIDE METHOD OrMeth()
    			?"iDrvTwo   OrMeth"
    			MYBASE.OrMeth
    		END METHOD
    		METHOD mDrvTwo(BYVAL c AS LONG)
    			?"mDrcTwo c = ";FORMAT$(c)
    		END METHOD
    
    		PROPERTY GET sDrvTwo() AS STRING
    			PROPERTY = sDrvTwo
    		END PROPERTY
    		PROPERTY SET sDrvTwo(BYVAL Param AS STRING)
    			sDrvTwo = Param
    		END PROPERTY
    
    	END INTERFACE
    END CLASS
    '------------------------------------------------------------------------------
    CLASS cDrvThree
    	INSTANCE sDrvThree AS STRING
    	INTERFACE iDrvThree : INHERIT cDrvTwo,iDrvTwo
    		OVERRIDE METHOD OrMeth()
    		    sDrvThree = "sDrvThree"
    			Me.sDrvTwo = "sDrvTwo"
    			Me.sDrvOne = "sDrvOne"
    			Me.sBase = "sBase"
    			?"iDrvThree OrMeth"
    			MYBASE.OrMeth
    		END METHOD
    		METHOD mDrvThree(BYVAL d AS LONG)
    			?"mDrvThree d = ";FORMAT$(d)
    		END METHOD
    		METHOD mDrvThree3()
    			?"mDrvThree3 LBase = ";FORMAT$(Me.LBase)
    'While this works ME SHOULD be used for iDrvThree method access and
    'MYBASE for all base class/interface method calls for clarity.
    			ME.mDrvOne(1)
    			MYBASE.mDrvOne(2)
    		END METHOD
    		METHOD PrintAllStrings()
    'Use Me to access base class instance variables
    			?"sBase      = ";Me.sBase
    			?"sDrvOne    = ";Me.sDrvOne
    			?"sDrvTwo    = ";Me.sDrvTwo
    'ME not needed here as sDrvThree is dfined in cDrvThree Class
    			?"sDrvThree  = ";sDrvThree
    		END METHOD
    
    		PROPERTY GET sDrvThree() AS STRING
    			PROPERTY = sDrvThree
    		END PROPERTY
    		PROPERTY SET sDrvThree(BYVAL Param AS STRING)
    			sDrvThree = Param
    		END PROPERTY
    
    	END INTERFACE
    END CLASS
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN() AS LONG
    	LOCAL oDrvThree AS iDrvThree
    	oDrvThree = CLASS "cDrvThree
    	oDrvThree.mDrvThree(17)
    'You have access to all methods and intance varaibles
    	oDrvThree.mDrvOne(55)
    	oDrvThree.mBase(66)
    	oDrvThree.LBase = 8
    	PRINT "-------------------"
    	oDrvThree.mDrvThree3
    	PRINT "-------------------"
    'Override methods test
    	oDrvThree.OrMeth
    	PRINT "-------------------"
    	oDrvThree.PrintAllStrings
    	PRINT "-------------------"
    'You have access to all varibles through the oDrvThree Object.
    	oDrvThree.sBase =     "sBase     Changed From PBMain"
    	oDrvThree.sDrvOne =   "sDrvOne   Changed From PBMain"
    	oDrvThree.sDrvTwo =   "sDrvTwo   Changed From PBMain"
    	oDrvThree.sDrvThree = "sDrvThree Changed From PBMain"
    	oDrvThree.PrintAllStrings
    	WAITKEY$
    END FUNCTION
    Attached Files
Working...
X