# Combining Items, where should the Code go?

**URL:** <https://forums.unrealengine.com/t/combining-items-where-should-the-code-go/101138>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [October 12, 2017, 3:29pm UTC](https://forums.unrealengine.com/t/combining-items-where-should-the-code-go/101138 "2017-10-12T15:29:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raildex](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Raildex](https://forums.unrealengine.com/u/Raildex)\
**Post date:** [October 12, 2017, 3:29pm UTC](https://forums.unrealengine.com/t/combining-items-where-should-the-code-go/101138/1 "2017-10-12T15:29:25Z")

</div>

Hi there, this is more of a “Where should I”-question rather than “How do I”-Question.

I have an Inventory, which consits of the Items (Array of ItemStack) and has Methods to Add/Remove Items or ItemStacks.  
I want some Items to be Cominable (but not every Item should be).  
The Question is: Where should I put the Logic (check if combinable etc.) for combining?  
First of all:  
Item A + Item B = Item B + Item A = Item C (Order doesn’t matter)

First, I thought of creating an “Combinable” Interface that Items should implement:

```auto

IsCombineableWith(Item i);
Item GetItemResult(Item toCombineWith); //You may combine one item with different items

```

However, that would mean that Item A and Item B need to implement this interface the exact same way (just the Item is replaced)

Another thought would be implementing a “Combinable Map” in the Inventory (Combine Logic would be in Inventory instead of Item).  
Here, I would use a Set of two Items as a Key and the Resulting Item as the Value. I just have to check for the Set (Do Sets always return the same Value when hashed? How is it treated when I put Item B first in a Set and then A. Sets usually don’t care about order)

Any suggestions?
