Page 1 of 1

Component Design vs Facade for L2PcInstance

Posted: Sun May 23, 2010 3:42 am
by issle88
I was wondering what do you guys think ( basically regarding performance-wise ) about the following two different implementations of a new feature in an existing code. Criterias that im interested in are:

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)} 
Someone once told me: "Its high time L2PcInstance goes on a diet". So the following compoment design came in mind and i wonder what would more advanced users have to say about it. The idea is that we hold every information inside new classes and only interface with the existing classes ( L2PcInstance ) with just a line of code just to monitor.

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));          }      }} 
Basically, we add the variables in the control object instead of the entity. Each seperate compoment, extends the base class ( PcInstance ) for its own benefit and purpose.

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.

Re: Component Design vs Facade for L2PcInstance

Posted: Sun May 23, 2010 6:31 am
by ThePhoenixBird
--moved to server discussion

Please keep offtopic for non-server related talk