You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implemented the Composite Design Pattern, including the `IGraphic`
interface, `Dot`, `CircleGraphic`, and `CompositeGraphic` classes.
Updated `Program.cs` to demonstrate the pattern with examples of
flat and nested composite structures.
Updated `README.md` to document the Composite pattern, its purpose,
usage, and related files. Added unit tests in `CompositeTests.cs`
to verify functionality, including nested composites.
Also included a demonstration of the Singleton pattern in
`Program.cs` using the `Logger` class.
@@ -93,6 +94,18 @@ Included patterns and brief docs
93
94
remote.SetChannel(10);
94
95
```
95
96
97
+
- Composite Pattern
98
+
- Purpose: Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions uniformly.
99
+
- Example: `DesignPatterns/Composite/*` contains `IGraphic` (leaf `Dot`, `CircleGraphic`) and `CompositeGraphic` which aggregates children.
100
+
- Usage snippet:
101
+
102
+
```csharp
103
+
var root = new CompositeGraphic();
104
+
root.Add(new Dot());
105
+
root.Add(new CircleGraphic());
106
+
Console.WriteLine(root.Draw()); // "Dot, Circle"
107
+
```
108
+
96
109
Tests
97
110
- Tests are written with xUnit in the `Tests` project.
0 commit comments