
Untitled
By: a guest on
Jul 10th, 2012 | syntax:
None | size: 1.01 KB | hits: 10 | expires: Never
package main
import "fmt"
type iPacket interface {
GetCommand() int;
Check() bool;
Add();
Divide();
}
type Packet struct {
Command int;
Sum int;
}
func (p *Packet) GetCommand() int {
return p.Command;
}
func (p *Packet) Check() bool {
return true;
}
func (p *Packet) Add() {
//STUB
}
func (p *Packet) Divide() {
//STUB
}
type DummyPacket struct {
Packet;
HalfA int;
HalfB int;
}
func (p *DummyPacket) Add() {
p.Sum = p.HalfA + p.HalfB;
}
func (p *DummyPacket) Divide() {
p.HalfA = p.Sum / 2;
p.HalfB = p.Sum / 2;
}
func HandleDummy(p DummyPacket) {
fmt.Printf("DummySum: %d",p.Sum);
}
func main() {
var pOrigin Packet;
pOrigin.Command = 1;
pOrigin.Sum = 10;
var pInterface iPacket;
pInterface = pOrigin;
if(pInterface.GetCommand()==1) {
pDestination := pInterface.(DummyPacket);
pDestination.Divide();
HandleDummy(pDestination);
}
}