extending Interface vs Structs

darkbeer

Beer is Good!
Reaction score
84
I got a little question about structs extending interfaces:

whats the difference between structs extending structs and structs extending interfaces?? is one of them faster/better ...? or doesnt it matter?

heres an example: which one is better?

JASS:
struct A
    unit u
    
    method A takes nothing returns nothing
    //some actions
    endmethod
endstruct

struct B extends A
endstruct



JASS:
interface Int
    method A takes nothing returns nothing
endinterface

struct A extends Int
    unit u
    
    method A takes nothing returns nothing
    //some actions
    endmethod
endstruct

struct B extends Int
    method A takes nothing returns nothing
    //some actions
    endmethod
endstruct


whats the difference between those two?
I would be able to call method A from each struct in both ways right?
 

Cohadar

master of fugue
Reaction score
209
For all standard purposes there is no difference.

I recommend you use structs extending structs,
interfaces are for people who know what and why are they doing it.
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
For all standard purposes there is no difference.

I recommend you use structs extending structs,
interfaces are for people who know what and why are they doing it.

What he said.

Untill the day you're like "Damn, this can't be done with StrExtStr", use those :)
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
Interfaces add additional functionality for methods. If you don't need that, use structs.
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
Interfaces add additional functionality for methods. If you don't need that, use structs.

Basically:
- a struct extending a struct cannot overwrite a method IIRC.
- a struct extending an interface can.

- a struct extending an interface can have its methods called as InterfaceName.MethodName(), allowing you to call any extending struct's methods without knowing for sure which struct your calling the method of.

JASS:

interface MyInt
    method MyMeth takes nothing returns nothing
endinterface

struct MyStructA extends MyInt
    method MyMeth takes nothing returns nothing
        call BJDebuMsg("Calling A's MyMeth")
    endmethod
endstruct

struct MyStructB extends MyInt
    method MyMeth takes nothing returns nothing
        call BJDebuMsg("Calling B's MyMeth")
    endmethod
endstruct

function TestStructs takes nothing returns nothing
    local MyInt array MI
    set MI[0] = MyStructA.create()
    set MI[1] = MyStructB.create()
    call MI[GetRandomInt(0,1)].MyMeth() // <---<< This would syntax if it weren't for interfaces,
// but now it knows that any struct extending MyInt has a MyMeth method and
// can thus call it on a MyInt without knowing which struct that extends it is being used.
endfunction
 

SFilip

Gone but not forgotten
Reaction score
634
> interfaces are for people who know what and why are they doing it.
So, basically, you're saying people who extend interfaces are cooler than people who extend structs? :rolleyes:

If you don't intend to use the base thing you're extending from (in your first example that would be using A), then there's no reason to make it a struct. You'd just be adding a couple of unneeded functions and variables to your map's code.
 

darkbeer

Beer is Good!
Reaction score
84
allright, i dont get everything yet, but ill see how far i come^^

THX to everyone :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top