Hi! I'm trying to define a list of objects that could be a binary tree or a Processtrees.
The binary tree is already defined and works fine, don't worry about it.

A Processtree is a binary tree generated by a Process, a Process is defined by a Name and a State

Processtree looks like this:

Class Processtree{
String ProcessName;
String StateName;
Binary tree ProcTree;
}

So I think that I don't need to worry about the Processtree, but I need to define a list of objects that could be a Binary tree or a Processtree.
The Processtree implementation may change, so I think I should define a common Tree interface and make Processtree and Binary tree implement it, but I don't know if I could define an ArrayList of this Tree..
I'm new to java, thanks in advance


Class Processtree{
String ProcessName;
String StateName;
Binary tree ProcTree;
}

So I think that I don't need to worry about the Processtree

if this is all the code you have in Processtree, you might want to worry though.
a better approach is to declare all your variables there private and to use getters and setters to get or manipulate their values

You can implement a common tree interface based on your current BTree class then you can have two options, First, you code PTree from common tree or Second you can inherit BTree to code your PTree if PTree is a kind of "Binary" tree.

The following is a tree interface:

interface CommonTree <T> {
public T getData();
public int getNodes();
public boolean IsEmpty();
public void Clear();

}

PTree is a kind of Binary tree so your Second solution works fine, but now my boss wants me to create a List of objects that can be a Binary tree or what he calls a Forest:
Forest{
NameProc
Array[s1,s2,...sn] of Binary tree
}

So I need to create a list that looks like this: BT-F-F-BT-F...
where BT is the Binary tree and F is a Forest.
Each forest is defined by the process name and an array of binary trees, the array is indexed by the states s1,..sn that are the states of the process, each state generates a different Binary tree..
This array is not the problem because I think I can use a map, but I don't know how to create a list of objects that are so different, could that be possible to create a list of binary trees and Forests using an interface?
Any help please

This article has been dead for over six months. Start a new discussion instead.