forked from anuradhawick/NukeIt-Tanker-Game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MessageParser.cs
40 lines (35 loc) · 1.02 KB
/
MessageParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// This package implments Chain of Responsibilities(COR) design pattern
namespace NukeIt_Tanker.MessageParser
{
abstract class MessageParser
{
public abstract bool handleMessageImpl(string message);
private MessageParser nextHandler;
// Instantiating the message parser
public MessageParser()
{
this.nextHandler = null;
}
// Getters and setters for the next handler
public MessageParser next_handler
{
get;
set;
}
public void handleMessage(string message)
{
// Handled by this handler
bool handledByThisNode = this.handleMessageImpl(message);
// If not grant to next handler
if (!handledByThisNode && this.nextHandler != null)
{
this.nextHandler.handleMessage(message);
}
}
}
}