Hi guys,
I need an architectural advice / help with the implementation of “reuseable” / “multiuse” UI Components. First of what do I mean with reuseable / multiuse:
I want UI components to be useable in several places/ui compositions. For example the player inventory, which is shown at the equipment screen or at a npc shop screen. Obviously, when the player transfers an item from his inventory different behaviour is needed, in the equipment screen we want to equip the transfered item (Player->Equip(item)) and in the shop we want to sell the item (Player->SellItem(NPC,item)).
My current Implementation looks like this:
Per UIComponent a seperate script (e.g. UIPlayerInventory, UICharacterEquipment, UIReadiedItem) with neccessary references (to the player/equipment/etc). Furthermore, Components that contain items/have slots implement the interface IItemSlotHolder.
Abstract class UIItemSlot that extends explicit ItemSlot Classes (UIInventoryItemSlot, UIEquipmentItemSlot, UIReadiedItemSlot). Those concrete Implementations are attached to corresponding prefabs. The ItemSlot has a reference to its parent ui component as a IItemSlotHolder.
A class for an Item (ItemStack), also attached to a prefab. OnEnabling/Moving the item prefab, it saves a reference to its parent slot as a GameObject.

Now for the interaction between those components, i made the item drag’n’droppable, meaning the class UIItemStack implements the interfaces IPointerDownHandler, IDragHandler, IBeginDragHandler, IEndDragHandler and the UIItemSlot implements the interface OnDropHandler with virtual (probably could/should be abstract) OnDrop implementation, where the extended classes (UIInventoryItemSlot/…) have their specific OnDrop implementation (e.g. Player->Equip(itemRecieved), Player->Unequip(itemReceived)).
Now the (rising) problem I see with this implementation:
There is a sender, the one where the ItemStack is dragged from, and a receiver, where the ItemStack is dropped on a ItemSlot.
The receiver knows explicitly what his UIComponent is, e.g. UIInventoryItemSlot’s UIComponent is the UIPlayerInventory. And the receiver can also get the type of the senders UIComponent (the eventData holds the ItemStack, which has a reference to its originating slot//concrete class for UIItemSlot, which has a reference to the parent IItemSlotHolder), however how would I implement different behaviour based on the senders type.
Of course i could go the route of if/switch statements based on the senders type, but having watched the jason weimann videos about the solid principle multiple times, i understood this could cause poor maintainability. For each new Composition where a UI is needed, i need to add a new branch to that statement.
A different solution i thought of was to have a seperate class, as a kind of processor, that determines the correct behaviour… this would prevent the need to edit every existing ui component if a new one is created. however its not truly prevented but rather shifted to a seperate class…so this seems to be a suboptimal solution aswell…
Any advices on archtecture are appreciated…
I hope I could explain my problem clearly, as I am not a native speaker, if there are any questions or need of concrete code let me know.
Thanks everyone in advance.