I only used the real world example so that the code I posted would be smaller. As a real programming example here.
I have a class TLED. Which is a single colour shape to be drawn on the screen
Type TLED'A Shape, a Colour, and a Position
'-----------------------------------------------
Field IsItOn :Int
Field Rotation :Int
Field TimeSinceChange :Int
Field Size :Float
Field Shape :TShape
Field Position :TBiFloat
Field Color :TRGB
'----------------------------------------------
Function Create:TLED (Position:TBiFloat,Size:Float,Color:TRGB,Shape:TShape,Rotation:Int = 0)
Local Temp:TLED = New TLED.Allocate(Position,Size,Color,Shape,Rotation)
Return Temp
End Function
'----------------------------------------------
Method Allocate:TLED (Position:TBiFloat,Size:Float,Color:TRGB,Shape:TShape,Rotation:Int = 0)
Self.TimeSinceChange = 0
Self.Shape = Shape
Self.Position = Position.CopyCreate()
Self.Color = Color
Self.Size = Size
Self.Rotation = Rotation
Self.IsItOn = False
End Method
'----------------------------------------------
Method TurnOn ()
If Self.IsItOn <> True
Self.IsItOn = True
Self.TimeSinceChange = 0
EndIf
End Method
'----------------------------------------------
Method TurnOff ()
If Self.IsItOn = True
Self.IsItOn = False
Self.TimeSinceChange = 0
EndIf
End Method
'----------------------------------------------
Method Switch:Int ()
If Self.IsItOn = True
Self.TurnOff
Else
Self.TurnOn
EndIf
Return Self.IsItOn
End Method
'----------------------------------------------
Method ChangeColor (Color:TRGB)
Self.Color = Color
End Method
'----------------------------------------------
Method ChangePosition (Position:TBiFloat)
Self.Position = Position
End Method
'----------------------------------------------
Method ChangeRotation (Rotation:Int)
Self.Rotation = Rotation
End Method
'----------------------------------------------
Method RotateBy (Amount:Int)
Self.Rotation:+ Amount
Self.Rotation:Mod 360
End Method
'----------------------------------------------
Method MoveByFloats (CX:Int,CY:Int)
Self.Position.AddFloats(CX,CY)
End Method
'----------------------------------------------
Method moveBy (Amount:TBiFloat)
Self.Position.Add (Amount)
End Method
'----------------------------------------------
Method Draw ()
SetOrigin (Self.Position.CX*PaneSize.CX , Self.Position.CY*PaneSize.CY)
SetRotation (Self.Rotation)
SetScale (PaneSize.CX*Self.Size,PaneSize.CY*Self.Size)
If Self.IsItOn = True
If Self.TimeSinceChange < 5
Self.TimeSinceChange:+ 1
Local Dim:Float = Self.TimeSinceChange / 5.0
SetColor (Self.Color.red * Dim ,Self.Color.green * Dim , Self.Color.blue * Dim)
Else
SetColor (Self.Color.red, Self.Color.green, Self.Color.blue)
EndIf
Else
SetColor(Self.Color.red / 5 , Self.Color.green / 5 , Self.Color.blue / 5)
EndIf
Self.Shape.Draw()
EndMethod
'----------------------------------------------
Method Resize(Multi:Float)
Self.Size:*Multi
End Method
'----------------------------------------------
EndType
OK so with this object I want to make a number display, now a number display "Contains" TLED. Its not an "Is A" realationship, at best its an "Are some" realationship so the TLEDs need to be Fields
Type TLedNumber'A calulator number
'----------------------------------------------
Const LedTop :Int = 0
Const LedTopRight :Int = 1
Const LedBottomRight :Int = 2
Const LedBottom :Int = 3
Const LedBottomLeft :Int = 4
Const LedTopLeft :Int = 5
Const LedMiddle :Int = 6
'----------------------------------------------
Global Shape:TShape = TLedNumber.CreateShape ()
Global LEDLogicArray:Int[][] = TLedNumber.CreateLedLogicArray()
'----------------------------------------------
Field Number :Int
Field LEDArray:TLED[7]
Field Position :TBiFloat
Field Color :TRGB
Field Size :Float
'----------------------------------------------
Function CreateLedLogicArray:Int[][] ()
Local Temp:Int[][]= [ [1 , 0 , 1 , 1 , 0 , 1 , 1 , 1 , 1 , 1]..
, [1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 1 , 1]..
, [1 , 1 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1]..
, [1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 , 1]..
, [1 , 0 , 1 , 0 , 0 , 0 , 1 , 0 , 1 , 0]..
, [1 , 0 , 0 , 0 , 1 , 1 , 1 , 0 , 1 , 1]..
, [0 , 0 , 1 , 1 , 1 , 1 , 1 , 0 , 1 , 1] ]
Return Temp
End Function
'----------------------------------------------
Function CreateShape:TShape()
Local Temp:TShape = New TShape.CreateFromArray..
([0.0, 4.0, 1.0, 2.0, 1.0, -2.0, 0.0 ,-4.0, -1.0, -2.0, -1.0, 2.0])
Return Temp
End Function
'----------------------------------------------
Function Create:TLedNumber (Size:Float=1,Color:TRGB=Null,Position:TBiFloat=Null)
Local Temp:TLedNumber = New TLedNumber.Allocate(Size,Color,Position)
Return Temp
End Function
'----------------------------------------------
Method Allocate:TLedNumber (Size:Float=1,Color:TRGB=Null,Position:TBiFloat=Null)
Self.Number = 0
Self.Size = Size
If Color
Self.Color = Color
Else
Self.Color = TRGB.Create(0,255,0)
EndIf
If Position
Self.Position = Position
Else
Self.Position = TBiFloat.Create (100,100)
End If
For Local Cell:Int = 0 To 6
Self.LEDArray[Cell] = TLED.Create (Self.Position,Self.Size,Self.Color,Self.Shape)
Next
Self.PositionCells
Self.SetNumber (Self.Number)
EndMethod
'----------------------------------------------
Method SetNumber(Number:Int)
Self.Number=Number
For Local Cell:Int = LedTop To LedMiddle
If Self.LEDLogicArray[Cell][Number] = 1
Self.LEDArray[Cell].TurnOn()
Else
Self.LEDArray[Cell].TurnOff()
EndIf
Next
End Method
'----------------------------------------------
Method PositionCells()
' LedTop
Self.LEDArray[LedTop].ChangeRotation (90)
Self.LEDArray[LedTop].MoveByFloats(0,-8)
' LedTopRight
Self.LEDArray[LedTopRight].ChangeRotation (0)
Self.LEDArray[LedTopRight].MoveByFloats(4,-4)
' LedBottomRight
Self.LEDArray[LedBottomRight].ChangeRotation (0)
Self.LEDArray[LedBottomRight].MoveByFloats(4,4)
' LedBottom
Self.LEDArray[LedBottom].ChangeRotation (90)
Self.LEDArray[LedBottom].MoveByFloats(0,8)
' LedBottomLeft
Self.LEDArray[LedBottomLeft].ChangeRotation (0)
Self.LEDArray[LedBottomLeft].MoveByFloats(-4,4)
' LedTopLeft
Self.LEDArray[LedTopLeft].ChangeRotation (0)
Self.LEDArray[LedTopLeft].MoveByFloats(-4,-4)
' LedMiddle
Self.LEDArray[LedMiddle].ChangeRotation (90)
'LedArray[LedMiddle].MoveBy ( 0,0)
End Method
'----------------------------------------------
Method Draw()
For Local Cell:Int = LedTop To LedMiddle
Self.LEDArray[Cell].Draw
Next
End Method
'----------------------------------------------
Method moveBy (Amount:TBiFloat)
Self.Position.Add(Amount)
For Local Cell:Int = LedTop To LedMiddle
Self.LEDArray[Cell].moveBy(Amount)
Next
End Method
'----------------------------------------------
Method MoveByFloat (CX:Int,CY:Int)
Self.Position.AddFloats(CX,CY)
For Local Cell:Int = LedTop To LedMiddle
Self.LEDArray[Cell].MoveByFloats(CX,CY)
Next
End Method
'----------------------------------------------
Method SetPosition (Amount:TBiFloat)
Self.Position = Amount
End Method
End Type
As you can see I need to provide a draw routine for the number, which fair enough just call the TLED draw
What I also have is "Aliens","Mothership","PlayerUnit" etc
Now each of these is also made of an TLED, which again I could just put as a field of the type. However I have said that the AlienLED for example, IS an LED.
Type TLEDAlien Extends TLED
'---------------------------------------------
Global AlienShape:TShape = TLEDAlien.CreateShape ()
'---------------------------------------------
Method Create:TLEDAlien (Position:TBiFloat=Null,Size:Float=1,Color:TRGB=Null,Shape:TShape=Null,Rotation:Int=0)
Super.Create (Position,Size,Color,Self.AlienShape,Rotation)
Return Self
End Method
'---------------------------------------------
Function CreateShape:TShape ()
Local MyShape:TShape=..
New TShape.CreateFromArray ([-2.5,0.5,-1.5,1.5,-1.5,-3.5,-2.5,-3.5])
MyShape.NextPolyArray ([2.5,0.5,1.5,1.5,1.5,-3.5,2.5,-3.5])
MyShape.NextPolyArray ([-1.5,-2.5,-0.5,-2.5,-0.5,-3.5,-1.5,-3.5])
MyShape.NextPolyArray ([1.5,-2.5,0.5,-2.5,0.5,-3.5,1.5,-3.5])
MyShape.NextPolyArray ([-.5,.5,.5,.5,.5,-.5,-.5,-.5])
MyShape.NextPolyArray ([-1.5,1.5,1.5,1.5,1.5,0.5,-1.5,0.5])
MyShape.NextPolyArray ([-1.5,-1.5,1.5,-1.5,1.5,-0.5,-1.5,-0.5])
MyShape.Resize(New TBiFloat.Create(2,2))
Return MyShape
End Function
End Type
What Im am doing is defineing the most basic things LEDs need, and then inhereted these to make each of the subsequent types. As you can see I dont have to worry about all that changecolour or rotation crap, because the TLEDAlien already has them (from TLED), I could easyerly make it a field, and then either write draw calls that call the fields draw, or call the fields draw directly. BUT TLedAlien.draw and TLed.Draw, are the same routine, so no extra work there
Your Points
1) If B doesnt need any colour, then you shouldnt try and inheret from a class that has colour. (This is a planing problem, not an inherent problem with Inhereting)
2) Type A
Type b extens A
Type c extends B
3) a) they are my base objects, so Iam the author, and I dont do that (well not very often)
b) Unless the rotation method is really stupidly done, you can just override it
4) Dont know. I wouldnt know how to do that in any languge.
But my understanding is that its the interface of the object that is important, and that has no relation to inheriting or not. Its surly, (If a problem at all), a problem about compilation
5) I have no idea what hes trying to say? If an object needed 10 colours, it needs 10 colours. (I think this was an argumnet used against useing types at all, rather than an argument against inheriting)
6) Errr and, thats not an arugument against you useing inhereting, is againt letting anyone else inhereting your stuff.
7) Is that about "Unions" cos it is totaly irrelivent to inhereting. Again I think that was an argument against types full stop.
And that entire monologue. He just need to learn how to use super. The entire monolouge is infact againt overriding in inhereted classes, and not inhereting in of itself
EDIT: In fact after reading you post again, and flash scanning the links, I think that your stance is against OOP, and not against inhereting.