One class Receiver
receives udp datagrams (more than 1000 datagrams every second).
To be OOP I should likely write such code in Receiver
public event EventHandler<NewDatagramEventArgs> NewMessage;
protected virtual void OnNewMessage(NewDatagramEventArgs e)
{
if (NewDatagram != null)
NewDatagram(this, e);
}
....
socket.Receive(result)
....
OnNewMessage(new NewDatagramEventArgs(result));
.....
Then I can attach any number of Consumers
to this class to be notified about new datagram.
In practice I always have exactly one consumer, so I can just write:
socket.Receive(result);
Consumer.Instance.NewDatagram(result);
And I pretty need to do things fast because it's trading software where each extra millisecond is extra money.
How much slower the first approach is? And how much ugly the second approach?