The composite pattern and document composition
While representing part-whole hierarchies (tree-structured), the composite design pattern describes a group of objects to be treated in a uniform manner, as if the leaf node and interior nodes are instances of the same object. A document object can contain multiple tables, and we can nest tables as well. This is an instance of a part-whole hierarchy, and composite design pattern is a natural choice here. To create a composite, we need to declare a base class, and all objects should be derived from this base class:
public abstract class TDocumentElement { public List<TDocumentElement> DocumentElements { get; set; } //------ The method given below is for implementing Visitor Pattern public abstract void accept(IDocumentVisitor doc_vis); //--- Code Omitted public TDocumentElement() { DocumentElements = new List<TDocumentElement...