I have AI and Player units and buildings. Now, for selection for example, AI and Player units and buildings are treated the same. I want to escape code duplication. To summarize, no matter a unit or a building, no matter AI or Player selection methods are same.
Options:
-
I can prefix the methods with PB, PU, AIB or AIU. That means player building, player unit, ai building or ai unit. And yeah you get code duplication this way. There are tiny differences only.
-
I can have one method for all, but it will take two bool arguments “player” and “unit”. If we have player == true and unit == true then i will execute code for player unit. If for example we have player == true and unit == false then i execute code for player building. Similar for ai units and buildings.
Let me know what you guys think
PS: Not Unity directly related maybe, but I am new to component-based programming so I am still not sure about such design questions