Experiment( vbscript.inheritance.asp )

Output

Q: Is Bob alive? A: True
Q: Is BlackNinja alive? A: True
Q: What's BlackNinja name? A: Nin Tendo
Q: How much energy BlackNinja possess? A: 100

>> BlackNinja attacks Bob <<

Q: How much energy BlackNinja still possess? A: 95
Q: Is Bob alive? A: False

>> Time to BlackNinja eat something <<

Q: How much energy BlackNinja still possess now? A: 97

Sources

/vbscript.inheritance.asp

<!--#include virtual="/lib/unit-tests.asp"-->
<!--#include virtual="/lib/axe/classes/Parsers/json2.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en">
    <head>
        <title>An ASP inheritance by delegation approach</title>
        <!--// meta tags //-->
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <!--// link tags //-->
        <link rel="stylesheet" type="text/css" media="screen" href="/lib/unit-tests.css" />
    </head>
    <body>
        <div id="container">
            <div id="container-hd">
                <h1>Experiment( vbscript.inheritance.asp )</h1>
            </div>
            <div id="container-bd">
 
<h2>Output</h2>
<div class="code"><pre><%
 
class Human
 
    public default function [new](byVal n, byVal a)
        name = n
        age  = a
        set [new] = Me
    end function
 
    public name
    public age
    public isAlive
    public energy
 
    public sub eat()
        energy = energy + 1
    end sub
 
    private sub Class_initialize()
        isAlive = true
        energy  = 1
    end sub
 
    private sub Class_terminate()
    end sub
 
end class
 
class Ninja' extends Human
 
    public default function [new](byVal n, byVal a, byVal s)
        call Parent.new(n, a)
        side = s
        set [new] = Me
    end function
 
    public side
 
    public sub attack(byRef Target)
        energy = energy - 5
        Target.isAlive = false
    end sub
 
    ' change parent methods
    public sub eat()
        Parent.energy = Parent.energy + 2
    end sub
 
    ' trivial inheritance stuff
    public property get name()
        name = Parent.name
    end property
 
    public property let name(byVal n)
        Parent.name = n
    end property
 
    public property get age()
        age = Parent.age
    end property
 
    public property let age(byVal a)
        Parent.age = a
    end property
 
    public property get isAlive()
        isAlive = Parent.isAlive
    end property
 
    public property let isAlive(byVal b)
        Parent.isAlive = b
    end property
 
    public property get energy()
        energy = Parent.energy
    end property
 
    public property let energy(byVal e)
        Parent.energy = e
    end property
 
    private Parent
 
    private sub Class_initialize()
        set Parent = new Human
 
        Parent.energy = 100
    end sub
 
    private sub Class_terminate()
        set Parent = nothing
    end sub
 
end class
 
 
 
 
 
 
 
 
 
 
' Using stuff
dim Bob : set Bob = (new Human)("Robert Weak", 25)
dim BlackNinja : set BlackNinja = (new Ninja)("Nin Tendo", "unknown", "EVIL")
 
Response.write( "Q: Is Bob alive? A: " )
Response.write( Bob.isAlive )' prints true
Response.write( vbNewline )
 
Response.write( "Q: Is BlackNinja alive? A: " )
Response.write( BlackNinja.isAlive )' prints true
Response.write( vbNewline )
 
Response.write( "Q: What's BlackNinja name? A: " )
Response.write( BlackNinja.name )' prints Nin Tendo
Response.write( vbNewline )
 
Response.write( "Q: How much energy BlackNinja possess? A: " )
Response.write( BlackNinja.energy )' prints 100
Response.write( vbNewline )
 
Response.write( vbNewline )
call BlackNinja.attack(Bob)
Response.write( ">> BlackNinja attacks Bob <<" ) : Response.write( vbNewline )
Response.write( vbNewline )
 
Response.write( "Q: How much energy BlackNinja still possess? A: " & BlackNinja.energy ) : Response.write( vbNewline )
Response.write( "Q: Is Bob alive? A: " & Bob.isAlive ) : Response.write( vbNewline )' Bob never had a chance ...
 
Response.write( vbNewline )
call BlackNinja.eat()
Response.write( ">> Time to BlackNinja eat something <<" ) : Response.write( vbNewline )
Response.write( vbNewline )
 
Response.write( "Q: How much energy BlackNinja still possess now? A: " & BlackNinja.energy ) : Response.write( vbNewline )
 
%></pre></div>
 
            </div>
            <div id="container-ft">
                <h2>Sources</h2>
                <h3><%= Request.ServerVariables("SCRIPT_NAME") %></h3>
                <div class="code"><%= geshify( loadTextFile( Server.mapPath( Request.ServerVariables("SCRIPT_NAME") ) ), "asp" ) %></div>
            </div>
        </div>
        <!--// javascript tags //-->
    </body>
</html>