-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathPrototype.cs
More file actions
31 lines (25 loc) · 748 Bytes
/
Prototype.cs
File metadata and controls
31 lines (25 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System.Collections.Concurrent;
namespace FlyweightPattern;
internal abstract class Flyweight
{
public abstract void Operation(int extrinsicstate);
}
internal class ConcreteFlyweight : Flyweight
{
public override void Operation(int extrinsicstate)
{
Console.WriteLine("operation in ConcreteFlyweight");
}
}
internal class UnsharedFlyweight : Flyweight
{
public override void Operation(int extrinsicstate)
{
Console.WriteLine("operation in UnsharedFlyweight");
}
}
internal class FlyWeightFactory
{
private readonly ConcurrentDictionary<string, Flyweight> _flyweights = new();
public Flyweight GetFlyweight(string name) => _flyweights.GetOrAdd(name, n => new ConcreteFlyweight());
}