code snippet 1
code snippet 2
code snippet 3
Above is my code of my game. Humanoid is like an NPC and player can sell item to him. So what I am trying to do in snippet 1 is to get all the items in the player inventory out first. At this point, I should be checking if the item can be sold or not. But, the problem I faced is that I could not use instanceOf/typecasting as it will violate SOLID Principle. How can I check if an Item is Sellable?
p/s: I cannot modify Item class as it is an engine code.
I had try to do type casting as previously I did not know that it will also violates SOLID Principle. At this point I really have no idea how to continue. The correct implementation should be able to add new SellAction(item) into the ActionList in code snippet 1.
Thank you in advance.
Gwin Lim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.