I am making a game and I have a Tile class that contains an Item.
public clas Tile{
Item item;
....
public void setItem(Item item){
this.item = item;
}
}
When I have a reference to the Tile I want to call the interact() method on the item. How can I do this without checking if the object is null. I don't think the Null Object pattern will work in this scenario because there will be mixed instance cohesion - a subclass of item that would represent an empty item would have an empty interact() method.
NoItemitem.