HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

interface & struct question

08-30-2007, 04:11 PM#1
MaD[Lion]
since im noob with vjass, i wanna know if its possible to declare methods with interface, and these methods will be automatically implemented into the structs that extends it. This way i wont need to redeclare the same methods for every struct tat extends the interface
08-30-2007, 07:14 PM#2
weaaddar
No, unfortuantly vJass doesn't support full blown inheritance. You can declare method stubs using the defualt parameter.
i.e.
Collapse JASS:
method myMethod takes nothing returns nothing defaults nothing
That way if you don't want to declare code for my method again you don't have.

Alternatively you can use a text macro
Collapse JASS:
//! textmacro MyMethod
method myMethod codeHere takes nothing returns nothing
//CODE HERE
endmethod
//! endtextmacro
then in your struct's body you'd just have to go
Collapse JASS:
//! runtextmacro MyMethod
Although in this example its a little more than copy and paste. Thats terribly ineffecient.

You could aternatively make a function handle this if its not handling private variables.
Collapse JASS:
function myMethod takes interface m returns nothing
The problem with this is virtual calls are pretty darn expensive :(
08-31-2007, 12:33 AM#3
MaD[Lion]
hm i dont want functions, cus i want methods, which sounds more logical with objects. But i think i know wat to do now
08-31-2007, 02:29 AM#4
Vexorian
Quote:
The problem with this is virtual calls are pretty darn expensive :(

Since I made a whole map that was based in doing hundreds of virtual calls every 0.025 seconds I would say it is no that expensive.

---
I need two things:
- An example in which this is necessary
- good syntax that could be added to interface so that "defaults" implemented code
08-31-2007, 02:57 PM#5
weaaddar
Well, Vex. I actually decided against using an abstract class and decided to go crazy and abstract things that would be a needed for each different type of hero object (I.e. one who can use a bag, one who can use an attributer,one who can use pshop) and instead make each one of them plug-inable state objects. Now I just need nice function delegates and the whole shebang could really be complete. I guess I should try to make each itemMenu object in a linked list so you don't need them to be in an explicit order. (so that way you can start using state 900 or something if your so daring and avoid danger, it would make finding state objects a bit more expensive but I seriously doubt your running through that many.)

But seriously why can't you just have classes that all use the same internal arrays, but every single time you want to use something that may not be in a instance force a call like if (typeid==classThatHasThatMember)then I doubt that would be too expensive
08-31-2007, 03:37 PM#6
MaD[Lion]
Quote:
Originally Posted by Vexorian
Since I made a whole map that was based in doing hundreds of virtual calls every 0.025 seconds I would say it is no that expensive.

---
I need two things:
- An example in which this is necessary
- good syntax that could be added to interface so that "defaults" implemented code


this is good when u have made something, example Object, and this object have some methods, like jumping, creating, moving. and i wanna make a struct called Actor that extends this with all the methods not needed to redeclare. This way i can add more stuffs into the actor struct faster and easier. and the users can also declare their type extends from my object when using the system. example creating struct called Bullet, Grenade ect...
And the syntax hmm... i think u should be able to declare it inside the interface tag, like in struct, and all structs tat extends it will automatically use this