That I understand, and perhaps I’m just having a “Senior Moment” here.
CLASS_A is the master class, with all the base logic / graphics etc…
while I mentioned CLASS_B, there is also CLASS_C and CLASS_D all of which inherit 90% from CLASS_A
The app has instances of all of those classes (ie. CLASS_A is used by itself as well)
What it sounds like you are suggesting, is to create a CLASS_Z which is never instantiated but used as the superclass for A-D
then have this
CLASS_Z
Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
RaiseEvent Paint(g, areas)
End Sub
CLASS_A thru CLASS_D
Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
reDraw g,<class specific parameter>
End Sub
add all the parameters to the event definition, and set a default value in the parameter definition
that way, you will ignore the first level of class, and use the parameter in the sub-subclasses or co-classes. as you need.
[quote=421700:@Jean-Yves Pochez]add all the parameters to the event definition, and set a default value in the parameter definition
that way, you will ignore the first level of class, and use the parameter in the sub-subclasses or co-classes. as you need.[/quote]
Ok… this is still not clear.
WHO raises the Event vs WHO implements the REDRAW method?
In the subclass add an event definition “paint(g as graphics)”. In the paint event of the subclass you add a “raiseevent paint(g)” where you need it. Then the parent class also has a paint event. The subclass can do additional stuff and the paint event in the parent class isn’t changed when there is no subclass.
If I’m understanding correctly, this should do the trick.
CLASS_A
Event Handlers
Paint(g as Graphics, areas() as RealBasic.Rect)
Event Definitions
Paint(g as Graphics, areas() as RealBasic.Rect)
Methods
reDraw(g as Graphics, param as Variant)
Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
reDraw g,<class specific parameter> // Does your drawing
RaiseEvent Paint(g, areas) // Raises the event for CLASS_B which is a subclass of CLASS_A
End Sub
I have been having trouble following your design pattern since the thread where you’d asked about it, so I’m having trouble making suggestions that are useful to you. If this doesn’t work out for you, I’ll need to see what you’re actually doing to help.
Generally what that means is you’ll need to return a value to determine if the behavior has been overridden.
[code]#tag Class
Protected Class Class_A
Inherits Canvas #tag Event
Sub Paint(g As Graphics, areas() As REALbasic.Rect)
If Not Paint(G) Then
Self.Redraw(G, “ABC”)
End If
End Sub #tag EndEvent
#tag Method, Flags = &h1
Protected Sub Redraw(G As Graphics, Tag As String)
End Sub
#tag EndMethod
#tag Hook, Flags = &h0
Event Paint(G As Graphics) As Boolean
#tag EndHook
End Class #tag EndClass
#tag Class
Protected Class Class_B
Inherits Class_A #tag Event
Function Paint(G As Graphics) As Boolean
Self.Redraw(G, “XYZ”)
Return True
End Function #tag EndEvent
End Class #tag EndClass
[/code]
Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
If InStr(Self.parent.name,"._wrapper_")=0 Then
debug "CLASS_A PAINT"
reDraw g,"BTN"
Else
RaiseEvent Paint(g, areas)
End If
End Sub
Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
If InStr(Self.parent.name,"._wrapper_")=0 Then
debug "CLASS_A PAINT"
reDraw g,"BTN"
Else
RaiseEvent Paint(g, areas)
End If
End Sub
[/quote]
There’s always multiple ways to solve a problem, but this seems clumsy since it relies on naming convention. Naming should be for organization, not for functionality.