wood burning stoves*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Query in Designing a system of classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Query in Designing a system of classes" Watch "Query in Designing a system of classes" New topic
Author

Query in Designing a system of classes

Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
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

Joined: Apr 16, 2008
Posts: 2187
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

Joined: Sep 29, 2008
Posts: 12617

You're re-implementing Quartz?
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Have you looked at java.util.Timer?


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
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

Joined: Aug 31, 2004
Posts: 295
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

Joined: Aug 31, 2004
Posts: 295
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

Joined: Jul 05, 2005
Posts: 1936
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

Joined: Aug 31, 2004
Posts: 295
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

Joined: Jul 05, 2005
Posts: 1936
You can have a look at source code of java.util.Timer if you want to learn.
 
wood burning stoves
 
subject: Query in Designing a system of classes
 
Similar Threads
Best suitable for the below scenaio : Interface/Abstract class
applet restriction question
Answers to IBM 486 sample test
UML Sample testing questions
Difference Between Design Pattern and Architecture