I want to represent an Edifact message in an OOP Language. An Edifact message has the following structure:

```
message      :=  [ ( segment | segmentgroup ) ]
segmentgroup : = [ ( segment | segmentgroup ) ]

```

In words: A message is a list of segments or segmentsgroups. Segments are the base element, segmentgroups have a recursive definition ( the same as the message).

How do I represnt this in OOP? I could introduce an artfical element, say messagenode, and make both segment and segmentgourp inherit from this element. Then message would be an array of messagenode. But that does't feel right for me, because when I process a message, would always do type checks, as i process them completly different. Is there a better solution?