Skip to main content
added 2 characters in body
Source Link
Ben Cottrell
  • 12.1k
  • 4
  • 33
  • 44

I have a tree data structure where each node has a name, an id, a type and a number of childschildren. Additionally each node has properties based on its type. Thereby each node with type A should only have children of Type B, C, D... and each node of type C should only have children with type D, E, F, etc.

Therefore I have implemented an abstract class containing all the common fields and subclasses for each type with an additional object for the uncommon properties.
The different types as well as the respective values are stored in an enum.
So I can check if a child can be added to a node using the values of the types defined in the enum.

Do you think it is fine to enforce the structure this way, or is there a better way to accomplsh that?

I have a tree data structure where each node has a name, an id, a type and a number of childs. Additionally each node has properties based on its type. Thereby each node with type A should only have children of Type B, C, D... and each node of type C should only have children with type D, E, F, etc.

Therefore I have implemented an abstract class containing all the common fields and subclasses for each type with an additional object for the uncommon properties.
The different types as well as the respective values are stored in an enum.
So I can check if a child can be added to a node using the values of the types defined in the enum.

Do you think it is fine to enforce the structure this way, or is there a better way to accomplsh that?

I have a tree data structure where each node has a name, an id, a type and a number of children. Additionally each node has properties based on its type. Thereby each node with type A should only have children of Type B, C, D... and each node of type C should only have children with type D, E, F, etc.

Therefore I have implemented an abstract class containing all the common fields and subclasses for each type with an additional object for the uncommon properties.
The different types as well as the respective values are stored in an enum.
So I can check if a child can be added to a node using the values of the types defined in the enum.

Do you think it is fine to enforce the structure this way, or is there a better way to accomplsh that?

I have a tree data structure where each node has a name, an id, a type and a number of childrenchilds. Additionally each node has properties based on its type. Thereby Thereby each node with type A should only have children of Type B, C, D... and each node of type C should only have children with type D, E, F.., etc.

Therefore I have implemented an abstract class containing all the commencommon fields and subclasses for each type with an additional object for the uncommenuncommon properties. The
The different types as well as the respective values are stored in an enum. So
So I can check if a child can beebe added to a node using the values of the types defined in the enum.

Do you thingthink it is fine to enforce the structure this way, or do you knowis there a better way to accomplsh that?

I have a tree data structure where each node has a name, an id, a type and a number of children. Additionally each node has properties based on its type. Thereby each node with type A should only have children of Type B, C, D... and each node of type C should only have children with type D, E, F...

Therefore I have implemented an abstract class containing all the commen fields and subclasses for each type with an additional object for the uncommen properties. The different types as well as the respective values are stored in an enum. So I can check if a child can bee added to a node using the values of the types defined in the enum.

Do you thing it is fine to enforce the structure this way or do you know a better way?

I have a tree data structure where each node has a name, an id, a type and a number of childs. Additionally each node has properties based on its type. Thereby each node with type A should only have children of Type B, C, D... and each node of type C should only have children with type D, E, F, etc.

Therefore I have implemented an abstract class containing all the common fields and subclasses for each type with an additional object for the uncommon properties.
The different types as well as the respective values are stored in an enum.
So I can check if a child can be added to a node using the values of the types defined in the enum.

Do you think it is fine to enforce the structure this way, or is there a better way to accomplsh that?

Source Link

Tree data structure where children can only be added based on their type

I have a tree data structure where each node has a name, an id, a type and a number of children. Additionally each node has properties based on its type. Thereby each node with type A should only have children of Type B, C, D... and each node of type C should only have children with type D, E, F...

Therefore I have implemented an abstract class containing all the commen fields and subclasses for each type with an additional object for the uncommen properties. The different types as well as the respective values are stored in an enum. So I can check if a child can bee added to a node using the values of the types defined in the enum.

Do you thing it is fine to enforce the structure this way or do you know a better way?