1)Abstraction, Modular code.
2)Performance
3)Sync problems minimizing.
Lets asume we have L2PcInstance and we want to add a new Event in our code. For that event, we want to:
1)Monitor onDie, and L2PcInstance event status ( joined or not ).
2)The kill count the player gets during the event.
A basic implementation:
We add a boolean variable in PCInstance ( boolean isInEvent ) together with its setter/getter, we add a killCountDuringEvent variable and we interface the Event.onKill( L2Character killer). So appart from our new files we will have inside L2PcInstance:
Code: Select all
private boolean isInEvent; private eventKillCount; //TODO: getters // setters public void onDie(L2Character killer){+ Event.onKill(killer)}
So here would be an alternative to the previous implementation.
Code: Select all
public class EventPcInstance{ private L2PcInstance player; private killCount; public EventPcInstance(L2PcInstance player) { this.player = player; killCount = 0; } //TODO: Getters/setters here.} public class Event{ public static FastMap<Int, EventPcInstance> eventPlayers = new bla bla ... public static void onDie(L2PcInstance killer ) { if(eventPlayers.containsKey(killer.getId()) { eventPlayers.get(killer.getId).increaseKillCount() } } public static void joinEvent(L2PcInstance activeChar) { if(!eventPlayers.containsKey(activeChar.getId()) { eventPlayers.add(activeChar.getId(), new EventPcInstance(activeChar)); } }}
Pros: We just interface with the whole system. We can do the same for every type of object we will need to extend in the system. Each compoment will provide its interface to the system and the system will realize it wherever it is needed.
Con: We lose in performance due to calls and a bit of a search time in the FastMap ? ( Is FastMap O ( 1 ) ? ). Is it much of a loss ?
Any opinions are welcome.