FAO Evak

BlitzMax Forums/BlitzMax Beginners Area/FAO Evak

FlameDuck(Posted 2005) [#1]
In that other thread you posted:

The most frustrating thing for me with Bmax has been translating basic tutorials from other languages into Bmax, in some ways it has probably accelerated my understanding, but its also meant that I have had to memorise a lot of concepts and then throw them away time and time again till I discovered what works.
I think maybe you've being trying with the wrong tutorials? I know I've said it before, but Bruce Eckels Thinking in Java 3rd Edition (a book you can download for free, written by a professional author and teacher) is a really, really excellent place to start learning OO concepts. If you have any trouble at all understanding some of the Java examples he provides, I would be more than happy to provide BlitzMAXified versions of them. (Provided you don't read much beyond Chapter 7 as some of the more advanced OO concepts are not currently available in BlitzMAX)

Something pretty tough without practice and being a visual person that isn't very good with words and numbers :)
That's another beautiful (and often overlooked) aspect of Object Oriented Programming (or more accurately Object Oriented Design), namely the Unified Modeling Language, UML. It gives you a graphical representation of how your program is going to look, before you've written a single line of code. It gives a much more 'visual' approach to programming than what one might traditionally use.

As for good books on the subject of UML, it's hard to whole-heartedly recommend one, although I hear Martin Fowlers book "UML Distilled" is pretty good. I'd probably borrow it from the library first tho', just to be on the safe side.


AdrianT(Posted 2005) [#2]
Hey Flameduck, thanks for the pointers. I'll be grabbing a copy of Bruce Eckels Thinking in Java 3rd Edition. See where that takes me in preperation for OOP :)


dynaman(Posted 2005) [#3]
Let me second Flameduck's recommendation - that is an excellent book.


JAW(Posted 2005) [#4]
I've just finished reading and rereading the first chapter of that book. It is an excellent intro to some OOP concepts for someone who already knows a bit about programming (though a few sections were a little unclear). Flameduck, let me see if I can go through my printed out copy and remember some of the questions I had...

So..is a Blitz 'type' basically a more limited 'class'? Is the underlying code creating a C++ class?

I understand inheritance, but what exactly is composition? It seems like something simple I already know. I just can't make sense of the explanation.

Is there a way to make an 'abstract' or 'interface' type in BlitzMax? Or does the compiler automatically do that if the new command is never used with that type?


FlameDuck(Posted 2005) [#5]
So..is a Blitz 'type' basically a more limited 'class'?
Yes. The words Type and Class are often used interchangable. The main reason for the predominant use of Class is that it's the term used originally in SIMULA, and subsequently in Java.

Is the underlying code creating a C++ class?
No. I believe BlitzMAX provides its own underlying (some would say simplified) OO model.

I understand inheritance, but what exactly is composition? It seems like something simple I already know.
It undoubtedly is. Say you're making a Pong game. Now a pong game consists (or is composed of) two bats and a ball. Thus the Game Type would have a Field for a Ball Type and 2 Bat Type. Example:
Type Ball
  Field x:int,y:int
.. and some methods ..
End Type

Type Bat
  Field y:int,side:int
.. and some methods ..
End Type

Type Game
  Field theBall:Ball
  Field player1:Bat
  Field player2:Bat
.. and some methods ..
End Type
Thus the Game type is a composition. A composition is a very strong bond, where the theBall, player1 and player2 objects cannot exsist on their own. Now in C++ this can give you alot of memory leaks. In Java, C# and BlitzMAX, it's no problem at all, as theBall, player1 and player2 are automatically killed by the Garbage Collector once the Game object is dereferenced (for example when a new game starts).

Is there a way to make an 'abstract' or 'interface' type in BlitzMax?
Abstract, yes -- Interface, no. Or rather not directly but you can fake it well enough by making a Type with no fields (only Constants allowed) and only Abstract methods.

Or does the compiler automatically do that if the new command is never used with that type?
No. But your program does throw an exception at runtime if you try and create an instance of an Abstract Type.


Hotcakes(Posted 2005) [#6]
making a Type with no fields (only Constants allowed)

Const's are available to a type?!?


FlameDuck(Posted 2005) [#7]
Const's are available to a type?!?
They are in Java. All fields in an Interface are by definition constants.


Hotcakes(Posted 2005) [#8]
So they aren't in blitz though?


BODYPRINT(Posted 2005) [#9]
Const's are available in Methods and Functions inside a type.

These Const's remain local to the method/function.