lundi 18 octobre 2021

A User specific version of a "data/blueprint" object

Sorry if the title is misleading.

I'm having difficulties in how to structure my project properly: I have a TaskManager, which handles all the Task objects and collect them in a map. Each Task object again contains a Map of Operation's. This is the structure:

public class TaskManager {

    private final Map<String, Task> tasks = new HashMap<>();

    public Task getTask(String task) {
        return tasks.get(task.toLowerCase());
    }
}



public class Task {
    private final Map<String, Operation> operations = new HashMap<>();
    private Operation firstOperation;

    public void startTask(User user) {
        if(firstOperation == null) {
            return;
        }

        firstOperation.start(user);
    }
}



public interface Operation {
    void start(User user);
}


My issue is, that now only one user can run a task, because operations are being tracked and handled per user. Therefore, I need a own version of either the task, or the operation for each User. I've found something called a deep copy? However it seemed to become messy, as the version I made here is simplified.

I'd appreciate any help with how I should structure this properly to become "multiple-users friendly"

Sorry if this is a beginner problem!

=====EDIT===== The Task object is loaded from a database or flat file. This object will only be modified by administrators.

A User, can find a Task they want to do, and start this task. When the user Start the Task, he must complete all the Operation's inside the Task. In order track the progress, and tell how far a User is, there must be a duplicated version of this Task, or the Individual Operation which will represent the User's progress.

For example: User1 has started task Message, and have completed 1 Operation. User2 has also started task Message, but have not completed any Operation yet.

The Operation classes will contain fields which will be modified as the User is doing that Operation. Multiple User's can do the same Task concurrently, which is why each User will need it's own version of it, since the fields will be modified from the "Blueprint" given to us in the start.

Sorry for my bad English, but hope it's understandable! Each individual user needs their own copy of some sort of the Task they are doing if I'm thinking correctly?

Aucun commentaire:

Enregistrer un commentaire