how to use overridden methods defined in a class, in another class?

128 Views Asked by At

I am having some problems in an exercise that I'm doing for the graphical interfaces course. I'm writing a program in F# defined in this way:

  • I have a class A, in which I override the method OnPaint;
  • I have another class B, in which I override the OnPaint method, OnMouse[Down/Move/Up] methods, etc.

I would use the overridden OnPaint method in A into the overridden OnPaint method defined in B (obviously, the OnPaint method in A, is defined in the class A, which means that I have to instantiate a type A object).

My question is: how can I do that? Do I need to define necessarily a method in A in which I pass a PaintEventArgs.Graphics parameter with the same tasks of the OnPaint method of A instead of override the OnPaint method in A?

An example: I've to do something like this:

type Ellipse() =
   ...
   override this.OnPaint e =
       e.Graphics.DrawEllipse(10.f, 10.f, 30.f, 30.f)

type classThatUseEllipse() =
   let ell = new Ellipse()
   ...
   override this.OnPaint e =
      ell.OnPaint(e)

Or something like this?:

type Ellipse() =
   ...
   let myOnPaint (e:PaintEventArgs) =
       e.Graphics.DrawEllipse(10.f, 10.f, 30.f, 30.f)

type classThatUseEllipse() =
   let ell = new Ellipse()
   ...
   override this.OnPaint e =
      ell.myOnPaint(e)

Or these two versions are the same?

I'm asking this because often the first version gave problems.

0

There are 0 best solutions below