Composite is structural design pattern that let ou compose objects into tree structure and then work with them as if they were individual objects.
Use Case
Tree like structure of objects (StaadModel, File System, etc.)
Organization of objects in a hierarchy (Company, Department, Military, etc.)
Code
publicclassNode{publicNode(stringdata){NodeData=data;}publicstringNodeData{get;privateset;}publicList<Node>Nodes{get;privateset;}=newList<Node>();publicoverridestringToString(){// Implementation for computing nodesvarsb=newSystem.Text.StringBuilder();sb.AppendLine("Start");sb.AppendLine(NodeData);foreach(varnodeinNodes){sb.AppendLine(node.ToString());}sb.AppendLine("End");returnsb.ToString();}}