I like OOP!

Miscellaneous Forums/General Discussion/I like OOP!

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Why extend a type?

Usually because you've got two types which contain chunks of similar code. In a GUI for example, all your gadgets will have methods like position, hide, show, parent, etc so you may as well write that code once and have it apply to all your types. Then when you decide you want to change it, you only have to change it once instead of twenty times.

How do you do - TType.something.something()? (Don't get the somethings.)

Normally, you don't. I guess the middle something could be a function or method which returns a type instance. So it might be First=TType.GetFirst() which returns the first one. Then you want to hide it so you say First.Hide() But you could do it all in one and just say TType.GetFirst().Hide() if that's all you need to do with that type instance.

WTF is polymorphism, Abstract Types?

Polymorphism is having a single function which can work on multiple different types. So in my example above, with the GUI and the hide method, you only have that one method, but it can be used on any type of gadget. You don't need to know which gadget type it is, and neither does your code.

Why do people use This.self()? Why self? How come? How do you use it?

Self refers to a type instance. When you call a method, that method is attached to a type instance, right? Sometimes you'll need to know which type instance it is and do something with it. That's what self is for.

Function Overloading? WTF is that?

Blitz can't do it so I wouldn't worry. But essentially it's having two ( or more ) functions with the same name but different parameters. So you might have two function called add. One takes two floats and one takes two ints. The compiler checks to see if you've passed ints. If you have, it uses the function which adds two ints. If you've provided two floats, it calls that instead. Blitz doesn't do it because Blitz has a lot of implicit type casting and it could get quite confusing where you wouldn't know which function might get called. It works well if the language is more strict about typing though.

I'm sure I've seen people use methods when an object isn't even created. How can this happen? Or did I read the code wrong?

Not methods, no. You can call type functions without creating a type instance, but a method MUST operate on a type instance.

Why can't I enjoy OOP like everybody else does?

Because it hasn't clicked yet. How can I best put this? Not sure if you're old enough, but let's try this..

Do you remember when Vic Reeves and Bob Mortimer were doing "Big Night Out" on Channel Four? Remember how everyone would rave about it? Then you watched an episode and thought it was complete bloody drivel? Then you watched a few more episodes, and it still seemed like drivel until one day it just clicked and you saw why everyone thought it was brilliant? It's a bit like that. It will just click eventually if you're patient. If you're not, it won't and you can continue coding procedural code instead. Mike ( Red ) probably won't forgive you, but most people won't care if you prefer procedural coding. OOP is only really to make your life easier. If you don't want to make your life easier or you just can get it to make your life easier, forget it.

[quoteWhy does everybody use ListAddLast List(somthing) instead of adding it to the begining of the list?[/quote]
No special reason, I don't think. Personally I just usually like them in the order I create them. Sometimes I count on it, but usually it wouldn't matter.