![]() |
Simulating Interfaces
One thing I was working on today was on a trade system for Relic. A criteria I valued was that I didn't want a central class for deciding what the trading does. So I was brain-storming, and I came across an idea from my Java course... Interfaces does not force how a function works... Instead, it mainly states that the object inherits a particular function subset.
So I was thinking of how I can imply this. My main goal is to have it so when I drag an item over a tradable object, it shows a trade-icon... So... I decided that what I needed was an interface for all items that can trade. In Graal, I know that classes contain codes inside them... But of particular interest, classes are in the joinedclasses variable ( which happens to be set both clientside and serverside ). So what I did was made the object join an interface. If the object complies to the interface, it stays in the class list... If it doesn't, it just removes itself. This way, in clientside... I know ALL objects that inherit the interface-tradable all contain the necessary code to handle such items. I hope this concept helps. ( This doesn't make a distinction between private/public functions, nor do they imply that the functions do what they should ) PHP Code:
PHP Code:
|
We must be long lost brothers, I believe we think similarly about scripting :D
Quote:
|
| All times are GMT +2. The time now is 06:32 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.