Minecolonies & Core-Rework-Refactoring-Madness

Hey everyone, after my last big refactor (if you missed it: here) I kinda slipped into a refactoring madness since our most essential class "Colony.java" which is the heart of minecolonies (It's the colony itself afterall) had 2200 lines of code, and, unfortunately not a very big part of this is documentation.

Therefore I decided to extract certain parts of the colony in manager classes.

Which are namely:


  • A Building Manager
    Responsible for, as the name says, managing all building interactions.
    Most importantly the list of buildings as well as creation and addition to the colony.

Therefore, from now on, you have to ask the colony for the BuildingManager to have access to the buildings or fields.
Additionally, the BuildingManager is responsible for writing the information to hard disk and not the colony itself anymore.


  • A Citizen Manager
    The CitizenManager is analogous to the BuildingManager responsible for all citizen based interactions, in this case again, most importantly the list of citizens.

With this, most importantly the CitizenManager spawns new citizen, removes them if necessary and as well writes and reads them from the disk.


  • An Achievement Manager
    The last manager is the Achievement and StatisticsManager it contains the list of achievements and statistics which are part of the colony but are synched to the player. With this the manager has the job to synch and store those achievements as well as to accept triggers.


Last but not least I also created a BarbarianManager which contains a few barbarian specific colony interactions.

But, this is not all.
It is quite nice to have those code extracted outside of the colony, which reduced the size of the colony.java to roughly 1200 which made it already way easier to see what matters, nevertheless, there I am planning to extract even more additional data in additional managers in the future to decrease the size further to the most important principles.

Besides that I defined Interfaces for each of the managers.

And the colony stores and accesses all the managers only through their interfaces.

This will allow us in the future to easily switch out significant parts of the managers or even the whole managers without affecting how it is being called. Which basically means, that as long as our new class follows the interface we will be able to change the whole manager without having to change anything in all the classes we're calling it.
Isn't that nice?

Besides that I fixed some small issues I found while debugging if everything went right.

I hope you enjoyed this rework, see you the next time!



Posted on Utopian.io - Rewarding Open Source Contributors

H2
H3
H4
3 columns
2 columns
1 column
10 Comments