Guest User

Untitled

a guest
Jan 12th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. type iPacket interface {
  6. GetCommand() int;
  7. Check() bool;
  8. Add();
  9. Divide();
  10. }
  11.  
  12. type Packet struct {
  13. Command int;
  14. Sum int;
  15. }
  16.  
  17. func (p *Packet) GetCommand() int {
  18. return p.Command;
  19. }
  20.  
  21. func (p *Packet) Check() bool {
  22. return true;
  23. }
  24.  
  25. func (p *Packet) Add() {
  26. //STUB
  27. }
  28.  
  29. func (p *Packet) Divide() {
  30. //STUB
  31. }
  32.  
  33. type DummyPacket struct {
  34. Packet;
  35. HalfA int;
  36. HalfB int;
  37. }
  38.  
  39. func (p *DummyPacket) Add() {
  40. p.Sum = p.HalfA + p.HalfB;
  41. }
  42.  
  43. func (p *DummyPacket) Divide() {
  44. p.HalfA = p.Sum / 2;
  45. p.HalfB = p.Sum / 2;
  46. }
  47.  
  48. func HandleDummy(p DummyPacket) {
  49. fmt.Printf("DummySum: %d",p.Sum);
  50. }
  51.  
  52. func main() {
  53. var pOrigin Packet;
  54. pOrigin.Command = 1;
  55. pOrigin.Sum = 10;
  56. var pInterface iPacket;
  57. pInterface = pOrigin;
  58. if(pInterface.GetCommand()==1) {
  59. pDestination := pInterface.(DummyPacket);
  60. pDestination.Divide();
  61. HandleDummy(pDestination);
  62. }
  63. }
Add Comment
Please, Sign In to add comment