Suppose that we have two classes, A and B, and two events OnPress and OnPressed. When I invoke OnPress both classes are a must-have, so I have an EventArgs that have a ref to both classes, but in OnPressed context only makes sense to have the ref to the class B. My doubt is, is better to have separated event args as:
public class PressEventArgs : EventArgs
{
public A a;
public B b;
}
public class PressedEventArgs : EventArgs
{
public B b;
}
And pass the right context to each event OR pass the PressEventArgs to both events only leaving the A class ref null?
CodePudding user response:
If different events have different arguments, then you should have different classes representing them.
Using the same class makes no sense. It violates several principles of software development.
If you had to pass a single number, you would never contemplate if passing a 2d coordinate and leaving the y-value zero would be a good fit. It isn't. You pass what you need to pass, not more, not less.