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 ...

Get .NET Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.