File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes design a POJO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "design a POJO" Watch "design a POJO" New topic

design a POJO

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 580
I like to design a POJO as follow

It should start itself when a particular event occurs. event may be changing in value of parameters of classes. POJO should listen the context for any event related to it, those event already defined in the POJO.

Class A {
int j;


Class B
Events :If any changes in value of J in the class A then below operation should fire

Viod df()
Do some operation

Reinhard Horn
Ranch Hand

Joined: Jun 04, 2007
Posts: 31
Hi Jacob,

you could use B as a listener class and register it in class A. So whenever the j-value
in A changes, A fires B's event Method doDf().

public interface AListener {

public void doDf(int j);


package javaapplication1;

public class B implements AListener {

public void doDf(int j) {


package javaapplication1;

import java.util.*;

public class A {

private int j;

private List<AListener> alisteners = new Vector<AListener>();

public List<AListener> getAlisteners() {
return alisteners;

public void addAlistener(AListener alistener) {

public int getJ() {
return j;

public void setJ(int j) {
this.j = j;

private void fireJChangedEvent() {
for (AListener alistener : this.getAlisteners()) {


package javaapplication1;

public class TestA {

public static void main(String[] args) {

B b1 = new B();
B b2 = new B();
A a1 = new A();




Jelle Klap

Joined: Mar 10, 2008
Posts: 1951

Look to the java.util.Observer / java.util.Observable pair for a kind of reference implementation of the Observer pattern. You could either use them directly or take a look at their API's for some inspiration, if you want to implement your own solution.
[ November 29, 2008: Message edited by: Jelle Klap ]

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
I agree. Here's the link:
subject: design a POJO
It's not a secret anymore!