I am trying to learn the best practices for methods in OOP in general. So lets say I have this code (C# by the way):
class Player
{
private Connection conn;
public Update(Keyboard key)
{
if(key.IsPressedKey("a"))
{
// should move
conn.SendPacketMovement(Movement.Left);
}
}
}
If I wanted to call a method inside the Connection class instance, what should I do? I dont want to add a return value to the Update method because it doesn't seem like a really good practice.
What should I do in that case, when I want several classes to do different things? Should I use delegates and events? If so, how do I subscribe to them. Should I subscribe to them when I create the instance of Player?