I have got a query in the design I am currently working on.
Scenario in brief
1. To automate set of tasks, performed at different times of the day.
2. Things we need to consider -- A core system to perform the tasks, and a scheduler to invoke them appropriately.
3. Tasks vary in type, like parsing a log file, invoking a batch file etc.
When I try to design the core set of classes that would perform the underlying tasks, I can think of the following approach.
I very much want to fine-tune my designing experience, as I am just starting with it.
1. The tasks are different in nature. However, to represent all tasks as entities, we can have a common base class.
2. The base class can be an "abstract" Task.
3. All the tasks will be derived from this. It would mean "ParseLogFile IS-A Task", for an instance.
4. We can have an interface "Performable" and a method "performTask()" which can be implemented by the "concrete" tasks.
Kindly validate this, and help me fine-tune it. Also, to extend this, I want to include the following features
1. A TaskFactory -- that instantiates a type of task, depending on the input (which could be time here)
2. A scheduler to trigger the instantiated task.
Kindly throw light on how we can go about, achieving a good design. I know, the question may sound little abstract, but I solicit your inputs. Thanks in advance.
Joined: Apr 16, 2008
To start, start to shift your mind into thinking about "objects" not classes. You want to design a system of objects.
You might want to study the source code for Apache Ant build tool, e.g. org.apache.tools.ant.Task
Thanks for the input. I will look at it for the scheduling part of it. Would you have any specific pointers to the core class design?
I'm not sure what you mean by core class design, you should have a look at java.util.Timer first. It provides the things you were thinking to implement out of the box.
Thanks again, for your reply.
True -- Timer and TimerTask can do it out of the box, but I am trying to write some code of my own here -- this is for learning purpose, and not for my business purpose. I have already tried Timer and TimerTask for some other purpose. This time, I want to try doing it on my own. I can even use windows scheduler for the time based scheduling part, but how best we can get the tasks automated was my question.
Joined: Jul 05, 2005
You can have a look at source code of java.util.Timer if you want to learn.