Thread: Interfaces?
View Single Post
  #2  
Old 05-07-2008, 02:58 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by PrinceOfKenshin View Post
Are there interfaces in GS2? I say this because i have been working with java a lot lately and i was wondering if there is like interfaces or something similar? Would someone care to explain if there is.
In Java, an interface is basically a "high" class which tells what you must do in the class, then leaves you to define it. This lets you make all sorts of objects under interface, say, Hurtable. For example, a turtle, a dog, and Stefan. You can then have an array of Hurtable which can contain turtle, dog, and Stefan and still call kill() to any of these without knowing what the class will do, only knowing it can do it (this way you don't have to have a separate array for each class).

I know you know this, for the benefit of those who don't.

In GS2, this would be rather pointless, as you can call whatever you want on anything you want. For example, I can call doSomething() to the Control NPC, even if it doesn't have this function. I'll get an error in RC, but I can still call it. This defeats the whole purpose of interfaces since you can call no matter what.

If you're trying to replicate this, perhaps have a class like this:

Code of script interface_bird
PHP Code:
function onCreated()
{
  
this.isBird true;

or so. You can then do something like this:
PHP Code:
join"bird_robin" );
join"interface_bird" ); 
You could have a script check if it was a bird by doing this:

PHP Code:
for ( temp.)
{
  if ( 
temp.a.isBird )
  {
    
temp.a.singPrettyMusic();
  }

So, this would let you replicate interfaces.

Like I said, this is pointless in GS2 as GS2 won't die like Java will; it will keep going and report an error. Java generally won't even compile this code to start with.

So no, there is no interface functionality in GS2 to my knowledge, and there is no reason to need it.

Hope this helps!
__________________
Reply With Quote