Hi there, I've recently come over from DBPro and wondered if there were any tutorials/introductions to OOP (I'm currently baffled by 'methods' and their purpose). Any help on this would be greatly appreciated!
Thanks
Thanks
Local myObject:Whatever = New Whatever '<- myObject is this particular objects identity. Local anotherObject:Whatever = New Whatever '<- Another Whatever object. It's identity is anotherObject.
DrawImage myObject.image , myObject.xPosition , myObject.yPosition ' Draws myObject to the backbuffer. DrawImage anotherObject.image , anotherObject.xPosition , anotherObject.yPosition ' Draws anotherObject to the backbuffer.[/quote]Now the cool trick here is that you can add all these objects to a datastructure (Array, List, Dictionary) and itterate over them all at once: [code]For Local i:Whatever = EachIn my dataStructure DrawImage i.image , i.xPosition , i.yPosition ' Draws all the Whatever objects added to dataStructure, one at a time. Next
Method Draw() DrawImage image , xPosition , yPosition ' Draws the Whatever object it was invoked on. EndMethodour loop from before is now reduced to:
For Local i:Whatever = EachIn my dataStructure i.draw ' Draws all the Whatever objects added to dataStructure, one at a time. NextWhich is much easier to read and uncerstand. Why is this better than Functions? The answer is polymorphism - but first, learn rule number one. :o>