This project once again hits the wall of needing multiple inheritance. This time, there is no workaround.
  • Each time the accumulator has changed, the code fires the AccumulatorChanged event, which receives a RegisterChangeEventArgs object. The RegisterChangeEventArgs contains old and new values for the accumulator.
  • Each time the accumulator is about to change, the code fires the AccumulatorChanging event, which receives a RegisterChangingEventArgs. This object is the same as the RegisterChangeEventArgs, but allows the new value to be changed (eg to simulate a random bit error in the hardware)
  • Each time a main memory cell has changed, the code fires the MemoryChanged event, which receives a MemoryChangeEventArgs object. This object contains the address, and old and new values.
  • Each time a main memory cell is about to change, the code fires the MemoryChanging event, which receives a MemoryChangingEventArgs. This is the same as a MemoryChangeEventArgs, but allows the new value to be changed (again for the same reasons.)

Let's try to make a decent inheritance hierarchy, so that it is easy to reuse event handlers.
  • The Changing arguments should derive from the Change arguments, so we can reuse a Changed event handler to also process a Changing event (eg to freeze execution so the user can inspect the processor state).
  • The Memory arguments should derive from the Register arguments so we can have an event handler to be triggered both when memory changes and when a register changes (eg to repaint the screen for the Changed event, or introduce random bit errors for the Changing event).

And now we are in trouble... The MemoryChangingEventArgs should therefore derive from both MemoryChangeEventArgs and RegisterChangingEventArgs. No matter how you try to add base classes with variants such as MemoryOrRegister, or AboutToChangeOrAlreadyChanged, you end up needing MemoryChangingEventArgs to derive from two of them, or worse, having base classes allow calls that end up throwing invalid operation exceptions at runtime.

Oh, and in cas you wonder, you can't use interfaces either, since all these must by convention derive from EventArgs, which is a class and not an interface...

Last edited Apr 12, 2012 at 12:29 PM by sleclercq, version 7

Comments

No comments yet.