You are not logged in.
I'm wondering if there is a design pattern suited to build trees from a given domain object.
public interface DomainObject {
public long getId();
}
public abstract class Displayable {
private DomainObject domainObject;
private Displayable parent;
private Vector children;
public Displayable(DomainObject domainObject, Displayable parent) {
this.domainObject = domainObject;
this.parent = parent;
this.children = new Vector();
}
public Displayable(DomainObject domainObject) {
this(domainObject, null);
}
public Displayable getParent() {
return parent;
}
public DomainObject getDomainObject() {
return domainObject;
}
public Displayable[] getChildren() {
return (Displayable[])children.toArray(new Displayable[children.size()]);
}
public void addChild(Displayable d) {
children.add(d);
}
}
Example:
DomainObject O
Displayable D (contains O)
D's parent is C
C's parent is B
B's parent is A
A does not have a parent
A --> B --> C --> D(O)
Method signature
public Displayable buildDisplayable(DomainObject domainObject);
So basically pass in a DomainObject (O) and spit out the Displayable (D), with the tree built up to the root (A).
Offline
sounds like a homework problem.
Offline
No kidding. Did they ask for it in a balanced red-black tree, or a b-tree?
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
No I graduated last year from college. I'm trying to improve our SWT/JFace GUI framework. That method signature is just something I thought about. I'm thinking using Factory Pattern will have to do considering I know ahead of time which subclasses of Displayable have parents and children.
Offline