I have object model, which describes an instructions for worker:
In my app I need a list of this instructions to guide worker in his job.
The types of instructions are very different, that's why data which is required to describe instruction can be different. For changing location I just need the location id, but for getting item I also need an item id, quantity and item name, alongside with location id.
So my model looks like that:
public class Instruction{
int locationId;
int itemId;
String itemName;
String quanity;
Type itemType; // can be Type.GET_ITEM, Type.CHANGE_LOCATION etc.
}
So I have the situation where I describe different entities with one model.
Should I live with that, or there's a way to eliminate duplication?
What I want is to keep the ability to store all instructions in a list, but to make models more clean.
How about something like this?
interface Instruction {}
class LocationInstruction implements Instruction {
int locationId;
public String toString() { return "Go to the location " + locationId; } ;
}
class ItemInstruction implements Instruction {
Item item;
public String toString() { return "Pick item " + item.toString(); } ;
}
class Item {
int itemId;
...
public String toString() { return "Item{itemId: "+itemId+"}" ;}
}
class Actions {
public List<Instruction> getInstructions();
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments