Monday, January 29, 2007

If I am a Java class

I will probably look like this:

public class Paul extends Sinner implement Male, Husband, Son,
Father, Citizen, Christian, Serializable, Runnable {
Logger logger = Logger.getInstance();
Vector officeTasks = new Vector();
static Paul me = null;

public static synchronized Paul getPaul() {
if (me == null) {
me = new Paul();
}
return me;
}

public void run() {
payBills();
beAHusband();
beAFather();
doCitizenDuties();
}

private void doWork() {
OfficeTask task = (OfficeTask) officeTasks.firstElement();
if (task != null && task.challenging()) {
if (task.getAssigner().equals(BOSS)) {
task.do(me);
}
} else if (task != null && task.impossible()) {
beSuperman();
}
}

protected void addOfficeTask(OfficeTask task) {
officeTasks.add(task);
}

private void beAFather() {
playWithKids();
readToKids();
watchTVwithKids();
}

private void beASon() {
honorParents();
}

private void beAHusband() {
loveWife();
talkToWife();
}

private void doCitizenDuties() {
do_In_Camp_Training();
if (office_calls) {
logger.log(logger.WARN, "Citizen module in progress, official work cannot be done concurrently.");
} else if (office_demands_work) {
if (work.canDelegate()) {
new thread() {
public void run() {
deleteToTeam(work);
}
}.start();
} else {
logger.log(logger.FATAL, "Work suffering from productivity.
Handphones not responding well and \
emails to be ignored to clear buffer.");
}
}
}

private void beSuperman() {
throw new MethodNotSupported();
}
}


I need to highlight the importance that I am only Runnable on a single CPU. So, I am not really doing real multi-tasking. I am just time-slicing.

And most importantly: I was not created to implement Cloneable interface. So, I cannot be at two places at any single instance of time. I am ... Serializable though.

No comments: