N
N
NikolayAlb2017-05-19 19:24:18
Software design
NikolayAlb, 2017-05-19 19:24:18

Create 2 related models or one depending on certain conditions, how to implement?

Hello. I can't figure out how best to solve this problem.
There are two tables:

  • Comments (task_id, text, position_x, position_y)
  • Tasks (title, priority, type, description)

I need to give users the ability to do things like this:
  • Create a task (Task) separately
  • Create a comment separately (it is attached to the picture by coordinates)
  • Create comment AS task

In fact, I need to give the opportunity, roughly speaking, to bind the task to coordinates. What is the best way to display this in code? I thought about the decorator, but I could not come up with a normal solution.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton, 2017-05-20
@avtel

interface Task{}
interface Comment{}
class TaskImpl  implements Task{}
class CommentImpl extends TaskImpl implements Task, Comment {}
class Service {
Task newTask {return new TaskImpl();}
Comment newComment(long taskId){return new CommentImpl(taskId);}
<T extends Z&X> commentAsTask(long taskId){return new CommentImpl(taskId);}
}

Something like that?

E
Elnur Urazymbetov, 2017-05-21
@u_elnur

NikolayAlb : Personally, I think that the task should be independent of the comment or image coordinates.
Therefore, I propose the following variant of the database structure:

Task:
    id
    title
    related_task_id
Image:
    id
    task_id
    path_to_file
    position_x = null
    position_y = null
    width = null
    length = null    
ImageComment:
    id
    image_id
    text
    position_x
    position_y
    width
    height

= null- Means that it is empty by default
Now I'll try to explain the logic:
As you can see. the task is an independent entity. But a task can be linked to another task. I'll explain this a little lower.
Each task has its own nested pictures. By default, fill in which task this picture belongs to and its path. The remaining fields are empty, for which I will also explain them below.
You can add comments to the picture. Comment text, x, y coordinates, width and height. I think everything is clear.
Now attention. You have two options for creating a task. The first is when you create it separately.
The second is when you create a task related to a certain area of ​​the picture (the picture is in another task).
With the first option, everything is standard.
In the second option, you will need to create a separate task, and related_taskindicate in which task you are creating this task.
Also, you will need to copy the picture that you selected into the newly created task. And in the additional fields specify the selected area.
When people open this new task, and this picture, you need to select an area according to the parameters.
I think you understand...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question