# Fixing starting times command by command and globally

I have a lot of Command objects. Each command has lots of Task objects. Tasks and commands are related. Each command wants to know which task belongs to it. Where each task wants to know which command it belongs to.

class Command:

def __init__(self, date):

"""
"""

"""
Remove the task from this command.  After calling this,
"""

def __init__(self, command:Command, duration:int):
self.duration = duration
self._command = command

@property
def command(self):
"""
Getter for self._command with sanity checking that
"""
return self._command

class Problem:
self._commands = commands



In the Problem object I feel there is some redundancy in the data between Commands and Tasks.

I fix starting times in two ways:

1. Fix the start time of tasks command by command.
This is why is a commands attribute in Problem.
2. Merge them and then fix the starting times.
This is why there is tasks attribute in Problem.

I need both ways to fix starting times. However, fixing the starting time of a task always depends on the deadline of the command to which it belongs.

I'm unsure if my design is good. Sometimes I need to go through the tasks command by command. Sometimes I need to consider all the tasks for the command they belong.
Is there a design pattern I can use?

• @Peilonrayz I fixed it – user228433 Jul 29 at 23:43
• Thank you :D looks good – Peilonrayz Jul 29 at 23:44

## Maintaining bidirectional relationships

Rather than this check:

    if not self._command.has_task(self):


it would be better to mark the task as orphaned by nulling out its command. In other words,

def remove_task(self, task):
"""
Remove the task from this command.  After calling this,

Having command as a simple, "public", possibly-None member on Task is simpler. At most, I would give this a type hint of Optional[Command] in the constructor.
Don't call date date; that's a commonly used class in a built-in library.
deadline should probably be of type datetime (not date), and duration should be of type timedelta, not int.