This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query in Designing a system of classes

 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,

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.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're re-implementing Quartz?
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked at java.util.Timer?
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Clarks wrote: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 James -- however, could you kindly explain, in what way this perspective shift will help me?
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:You're re-implementing Quartz?


Thanks for your reply.

I am actually not implementing Quartz. I was considering using Quartz for the "scheduling" part of my mini-mini app.
However, I first wanted to get my design proper, that's why I posted here.
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kengkaj Sathianpantarit wrote:Have you looked at java.util.Timer?


Kengkaj,

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?
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramaswamy Srinivasan wrote:
Kengkaj Sathianpantarit wrote:Have you looked at java.util.Timer?


Kengkaj,

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.
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kengkaj Sathianpantarit wrote:
Ramaswamy Srinivasan wrote:
Kengkaj Sathianpantarit wrote:Have you looked at java.util.Timer?


Kengkaj,

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.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have a look at source code of java.util.Timer if you want to learn.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic