Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why properties are not declarables in interfaces

In Actionscript 3 I can't declare vars in Interfaces. I don't get it. I know i can work this around by defining getters and setters, but what if i just want a simple public property? I usually use getters and setters if there is something to do when i set or get a property, but what if i just want to store a value?

like image 548
Carlo Avatar asked Nov 06 '22 20:11

Carlo


1 Answers

You can put it like this: interfaces exist because in your language you can't inherit from multiple abstract base classes. If AS3 would have allowed you to do that, it would probably not have 'interfaces', but 'pure abstract classses'.

In other words, having properties implementation in your interface would lead to name clashes and from there to other multiple inheritance problems (diamond).

However, having just a getter or a setter with no implementation should work.

public interface I { function get A():int; }

(I don't have the AS3 compiler at hand)

like image 53
Vlagged Avatar answered Nov 15 '22 07:11

Vlagged