Component Design vs Facade for L2PcInstance

This is not a Support area! Discuss about the Server here. Non-Server related discussion goes in Off-Topic Discussion.
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
issle88
Posts: 36
Joined: Sat Apr 01, 2017 2:35 pm

Component Design vs Facade for L2PcInstance

Post 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.
User avatar
ThePhoenixBird
L2j Inner Circle
L2j Inner Circle
Posts: 1857
Joined: Fri May 27, 2005 5:11 pm

Re: Component Design vs Facade for L2PcInstance

Post by ThePhoenixBird »

--moved to server discussion

Please keep offtopic for non-server related talk
Reese2777
Posts: 1
Joined: Thu May 09, 2024 11:46 am

Re: Component Design vs Facade for L2PcInstance

Post by Reese2777 »

When considering the architecture for L2PcInstance, there's a notable distinction between Component Design and Facade. You can More info about Component Design reveals a granular approach, where each aspect is meticulously crafted and encapsulated, promoting modularity and ease of maintenance. Conversely, delving into the intricacies of Facade sheds light on a higher-level abstraction, simplifying interactions by providing a unified interface. Within the context of L2PcInstance, index-driven Component Design could optimize performance by efficiently managing data access and manipulation at a lower level. On the other hand, leveraging Facade could streamline complex operations, allowing for a more intuitive and concise development experience. Ultimately, the choice between Component Design and Facade hinges on the specific requirements and goals of the project.
Post Reply