-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
1289 lines (1092 loc) · 37.9 KB
/
Program.cs
File metadata and controls
1289 lines (1092 loc) · 37.9 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
//구조 패턴들 모음
//클래스나 객체를 조합하여 더 큰 구조를 만드는 패턴
//서로 다른 인터페이스를 지닌 2개의 객체를 묶어 단일 인터페이스로 제공하거나 객체를 묶어 새로운 기능을 제공하는 패턴
namespace StructuralPattern
{
//클래스의 인터페이스를 다른 클라이언트의 인터페이스로 바꿈, 어뎁터는 클래스가 동시에 동작하게 만들어줌 어뎁터가 없으면 인터페이스간 호환이 되지 않아 동시에 작동하지 않음
namespace Adapter
{
#region 구조
/// <summary>
/// Target(화합물)
/// - 특정 상황에 맞는 인터페이스가 정의된 것, Client에서 사용될 인터페이스
/// Adapter(물질)
/// - 인터페이스를 어뎁티에 있는 인터페이스를 타겟 인터페이스에 연동시킴
/// Adaptee(화학 데이터 베이스)
/// - 적용시킬 인터페이스 들고 있는 곳
/// Client (AdapterApp)
/// - Target인터페이스에 맞춰 다른 오브젝트와 함께 행동이 개시되는 곳
/// </summary>
class AdapterEx
{
static void Main()
{
Target target = new AdapterInstance();
target.Request();
Console.ReadKey();
}
}
class Target
{
public virtual void Request()
{
Console.WriteLine("타겟이 요청을 의뢰함");
}
}
class AdapterInstance : Target
{
Adaptee _adaptee = new Adaptee();
public override void Request()
{
base.Request();
_adaptee.SpecificRequest();
}
}
class Adaptee
{
public void SpecificRequest()
{
Console.WriteLine("특정 요구 요청");
}
}
#endregion
#region 예시
class AdapterRealMain
{
static void Main()
{
Compound unknown = new Compound("Unknown");
unknown.Display();
Compound water = new RichCompound("Water");
water.Display();
Compound benzene = new RichCompound("Benzene");
benzene.Display();
Compound ethanol = new RichCompound("Ethanol");
ethanol.Display();
Console.ReadKey();
}
}
class Compound
{
protected string _chemical;
protected float _boilingPoint;
protected float _meltingPoint;
protected double _molecularWeight;
protected string _molecularFormular;
public Compound(string chemical)
{
this._chemical = chemical;
}
public virtual void Display()
{
Console.WriteLine($"Compound : {_chemical}");
}
}
class RichCompound : Compound
{
ChemicalDatabank _bank;
public RichCompound(string name) : base(name)
{
}
public override void Display()
{
_bank = new ChemicalDatabank();
_boilingPoint = _bank.GetCriticalPoint(_chemical, "B");
_meltingPoint = _bank.GetCriticalPoint(_chemical, "M");
_molecularWeight = _bank.GetMolecularWeight(_chemical);
_molecularFormular = _bank.GetMolecularStructure(_chemical);
base.Display();
Console.WriteLine($"Formula : {_molecularFormular}");
Console.WriteLine($"Weight : {_molecularWeight}");
Console.WriteLine($"Melting pt : {_meltingPoint}");
Console.WriteLine($"Boiling pt : {_boilingPoint}");
}
}
class ChemicalDatabank
{
public float GetCriticalPoint(string compound, string point)
{
if(point == "M")
{
switch (compound.ToLower())
{
case "water": return 0;
case "benzene": return 5.5f;
case "ethanol": return -114.1f;
default: return 0;
}
}
else
{
switch (compound.ToLower())
{
case "water": return 100;
case "benzene": return 80.1f;
case "ethanol": return -78.3f;
default: return 0;
}
}
}
public string GetMolecularStructure(string compound)
{
switch (compound.ToLower())
{
case "water": return "H2O";
case "benzene": return "C6H6";
case "ethanol": return "C2H5OH";
default: return "";
}
}
public double GetMolecularWeight(string compound)
{
switch (compound.ToLower())
{
case "water": return 18.015;
case "benzene": return 78.1134;
case "ethanol": return 46.0688;
default: return 0;
}
}
}
#endregion
}
//abstract의 의존성을 줄여 두 객체의 의존성을 줄임
namespace Bridge
{
#region 구조
///<summary>
/// Abstraction (BusinessObject) : 추상 클래스의 인터페이스, 오브젝트 타입의 참조를 포함
/// RefinedAbstraction(CustomersBusinessObject) : Abstraction에서 정의된 인터페이스 확장
/// Implementor(DataObject) : 객체에 적용할 인터페이스가 정의된 클래스, 이 인터페이스는 Abstraction의 인터페이스와 연관이 있을 필요는 없음, 두 인터페이스가 다름, Implementor 인터페이스는 오직 primitive 동작만 정의하고, Abstraction은 primitive들 기반으로 보다 정교한 동작이 정의됨
/// ConcreteImplementor(CustomersDataObject) : Implementor의 interface를 객체에 지정함
///</summary>
class BridgeStructureMain
{
static void Main()
{
Abstraction ab = new RefinedAbstraction();
ab.Implementor = new ConcreteImplementorA();
ab.Operation();
ab.Implementor = new ConcreteImplementorB();
ab.Operation();
Console.ReadKey();
}
}
class Abstraction
{
protected Implementor implementor;
public Implementor Implementor
{
set { implementor = value; }
}
public virtual void Operation()
{
implementor.Operation();
}
}
abstract class Implementor
{
public abstract void Operation();
}
class RefinedAbstraction : Abstraction
{
public override void Operation()
{
implementor.Operation();
}
}
class ConcreteImplementorA : Implementor
{
public override void Operation()
{
Console.WriteLine("ConcreteImplementorA Operation");
}
}
class ConcreteImplementorB : Implementor
{
public override void Operation()
{
Console.WriteLine("ConcreteImplementorB Operation");
}
}
#endregion
#region 예시
class BridgeRealMain
{
static void Main()
{
Customer customers = new Customer("Chicago");
customers.Data = new CustomerData();
customers.Show();
customers.Next();
customers.Show();
customers.Next();
customers.Show();
customers.Add("Henry Velasquez");
customers.ShowAll();
Console.ReadKey();
}
}
class CustomerBase
{
DataObject _dataObject;
protected string group;
public CustomerBase(string group)
{
this.group = group;
}
public DataObject Data
{
get { return _dataObject; }
set { _dataObject = value; }
}
public virtual void Next()
{
_dataObject.NextRecord();
}
public virtual void Prior()
{
_dataObject.PriorRecord();
}
public virtual void Add(string customer)
{
_dataObject.AddRecord(customer);
}
public virtual void Show()
{
_dataObject.ShowRecord();
}
public virtual void ShowAll()
{
Console.WriteLine("Customer Group" + group);
_dataObject.ShowAllRecord();
}
}
class Customer : CustomerBase
{
public Customer(string group) : base(group)
{
}
public override void ShowAll()
{
Console.WriteLine();
Console.WriteLine("-------------------");
base.ShowAll();
Console.WriteLine("-------------------");
}
}
abstract class DataObject
{
public abstract void NextRecord();
public abstract void PriorRecord();
public abstract void AddRecord(string name);
public abstract void DeleteRecord(string name);
public abstract void ShowRecord();
public abstract void ShowAllRecord();
}
class CustomerData : DataObject
{
List<string> _customers = new List<string>();
int _current = 0;
public CustomerData()
{
_customers.Add("Jim Jones");
_customers.Add("Samual Jackson");
_customers.Add("Allen Good");
_customers.Add("Ann Stills");
_customers.Add("Lisa Giolani");
}
public override void NextRecord()
{
if(_current<= _customers.Count - 1)
{
_current++;
}
}
public override void PriorRecord()
{
if (_current > 0)
{
_current--;
}
}
public override void AddRecord(string name)
{
_customers.Add(name);
}
public override void DeleteRecord(string name)
{
_customers.Remove(name);
}
public override void ShowRecord()
{
Console.WriteLine(_customers[_current]);
}
public override void ShowAllRecord()
{
foreach(var customer in _customers)
{
Console.WriteLine(" " + customer);
}
}
}
#endregion
}
//여러 개의 객체들로 구성된 복합 객체, 단일 객체를 클라이언트에서 구별없이 다룰 수 있게 만드는 패턴
namespace Composite
{
#region 구조
/// <summary>
/// Component (DrawingElement) : 오브젝트의 성분에 들어갈 인터페이스 정의, 모든 클래스에 공통되는 인터페이스로 기본 성질등을 내포, 하위 성분에 접근할 수 있는 인터페이스 정의, 성분의 부모에 접근할 수 있는 인터페이스가 포함될 수 있음
/// Leaf(PrimitiveElement) : Leaf 객체의 컴포넌트 성분, 하단 성분 없음, 기본 객체 행동이 포함됨
/// Composite(CompositeElement) : 하위 성분이 포함된 작동이 정의됨, 하위 성분 가지고 있음, 하위와 연관된 작동함수가 포함됨
/// Client(CompositeApp) : Component의 interface들을 조합하여 객체를 만듦
/// </summary>
class CompositStructureMain
{
static void Main()
{
Composite root = new Composite("root");
root.Add(new Leaf("Leaf A"));
root.Add(new Leaf("Leaf B"));
Composite comp = new Composite("Composite X");
comp.Add(new Leaf("Leaf XA"));
comp.Add(new Leaf("Leaf XB"));
root.Add(comp);
root.Add(new Leaf("Leaf C"));
Leaf leaf = new Leaf("Leaf D");
root.Add(leaf);
root.Remove(leaf);
root.Display(1);
Console.ReadKey();
}
}
abstract class Component
{
protected string name;
public Component(string name)
{
this.name = name;
}
public abstract void Add(Component c);
public abstract void Remove(Component c);
public abstract void Display(int depth);
}
class Composite : Component
{
List<Component> _children = new List<Component>();
public Composite(string name) : base(name)
{
}
public override void Add(Component c)
{
_children.Add(c);
}
public override void Remove(Component c)
{
_children.Remove(c);
}
public override void Display(int depth)
{
Console.WriteLine(new string('-', depth) + name);
foreach(var component in _children)
{
component.Display(depth + 2);
}
}
}
class Leaf : Component
{
public Leaf(string name): base(name)
{
}
public override void Add(Component c)
{
Console.WriteLine("잎사귀에 더할 수 없음");
}
public override void Remove(Component c)
{
Console.WriteLine("잎사귀에서 제거할 수 없음");
}
public override void Display(int depth)
{
Console.WriteLine(new string('-', depth) + name);
}
}
#endregion
#region 예시
class CompositeRealMain
{
static void Main()
{
CompositeElement root = new CompositeElement("Picture");
root.Add(new PrimitiveElement("Red Line"));
root.Add(new PrimitiveElement("Blue Circle"));
root.Add(new PrimitiveElement("Green Box"));
CompositeElement comp = new CompositeElement("Two Circle");
comp.Add(new PrimitiveElement("Black Circle"));
comp.Add(new PrimitiveElement("White Circle"));
root.Add(comp);
PrimitiveElement pe = new PrimitiveElement("Yellow Line");
root.Add(pe);
root.Remove(pe);
root.Display(1);
Console.ReadKey();
}
}
abstract class DrawingElement
{
protected string name;
public DrawingElement(string name)
{
this.name = name;
}
public abstract void Add(DrawingElement d);
public abstract void Remove(DrawingElement d);
public abstract void Display(int indent);
}
class PrimitiveElement : DrawingElement
{
public PrimitiveElement(string name): base(name)
{
}
public override void Add(DrawingElement d)
{
Console.WriteLine("PrimitiveElement에는 성분을 더할 수 없음");
}
public override void Remove(DrawingElement d)
{
Console.WriteLine("PrimitiveElement에서 성분을 없앨 수 없음");
}
public override void Display(int indent)
{
Console.WriteLine(new string('-', indent) + name);
}
}
class CompositeElement: DrawingElement
{
List<DrawingElement> elements = new List<DrawingElement>();
public CompositeElement(string name) : base(name)
{
}
public override void Add(DrawingElement d)
{
elements.Add(d);
}
public override void Remove(DrawingElement d)
{
elements.Remove(d);
}
public override void Display(int indent)
{
Console.WriteLine(new string('-', indent)+ "+ " + name);
foreach(var d in elements)
{
d.Display(indent + 2);
}
}
}
#endregion
}
//객체의 결합으로 기능을 동적으로 유연하게 확장할 수 있게 하는 패턴
namespace Decorator
{
#region 구조
/// <summary>
/// Component (LibraryItem) : 객체에 동적으로 더해질 수 있는 인터페이스 정의
/// ConcreteComponent(Book, Video) : 반응 할 수 있는 추가 행동 방식이 정의된 객체
/// Decorator (Decorator) : Component 객체의 참조가 있고 Component의 인터페이스에서 따온 것..
/// ConcreteDecorator (Borrowable) : 반응양식 성분
/// </summary>
class DecoratorStructuralMain
{
static void Main()
{
ConcreteComponent c = new ConcreteComponent();
ConcreteDecoratorA d1 = new ConcreteDecoratorA();
ConcreteDecoratorB d2 = new ConcreteDecoratorB();
//데코레이터 연결
d1.SetComponent(c);
d2.SetComponent(d1);
d2.Operation();
Console.ReadKey();
}
}
abstract class Component
{
public abstract void Operation();
}
class ConcreteComponent : Component
{
public override void Operation()
{
Console.WriteLine("ConcreteComponent.Operation()");
}
}
abstract class Decorator : Component
{
protected Component component;
public void SetComponent(Component component)
{
this.component = component;
}
public override void Operation()
{
component?.Operation();
}
}
class ConcreteDecoratorA : Decorator
{
public override void Operation()
{
base.Operation();
Console.WriteLine("ConcreteDecoratorA.Operation()");
}
}
class ConcreteDecoratorB : Decorator
{
public override void Operation()
{
base.Operation();
AddedBehavior();
Console.WriteLine("ConcreteDecoratorB.Operation()");
}
void AddedBehavior()
{
}
}
#endregion
#region 예시
class DecoratorRealMain
{
static void Main()
{
Book book = new Book("Worley", "Inside ASP.NET", 10);
book.Display();
Video video = new Video("Spielberg", "Jaws", 23, 92);
video.Display();
Console.WriteLine("\n비디오를 대여할 수 있습니다");
Borrowable borrowvideo = new Borrowable(video);
borrowvideo.BorrowItem("고객 1");
borrowvideo.BorrowItem("고객 2");
borrowvideo.Display();
Console.ReadKey();
}
}
abstract class LibraryItem
{
int _numCopies;
public int NumCopies
{
get { return _numCopies; }
set { _numCopies = value; }
}
public abstract void Display();
}
class Book : LibraryItem
{
string author;
string title;
public Book(string author, string title, int numCopies)
{
this.author = author;
this.title = title;
this.NumCopies = numCopies;
}
public override void Display()
{
Console.WriteLine("\nBook----------");
Console.WriteLine($"Author : {author}");
Console.WriteLine($"Title : {title}");
Console.WriteLine($"Copies : {NumCopies}");
}
}
class Video : LibraryItem
{
string director;
string title;
int playtime;
public Video(string director, string title, int numCopies, int playtime)
{
this.director = director;
this.title = title;
this.NumCopies = numCopies;
this.playtime = playtime;
}
public override void Display()
{
Console.WriteLine("\nVideo---------");
Console.WriteLine($"Director : {director}");
Console.WriteLine($"Title : {title}");
Console.WriteLine($"Copies : {NumCopies}");
Console.WriteLine($"PlayTime : {playtime}");
}
}
class DecoratorB : LibraryItem
{
protected LibraryItem libraryItem;
public DecoratorB(LibraryItem libraryItem)
{
this.libraryItem = libraryItem;
}
public override void Display()
{
libraryItem.Display();
}
}
class Borrowable : DecoratorB
{
List<string> borrowers = new List<string>();
public Borrowable(LibraryItem libraryItem) : base(libraryItem)
{
}
public void BorrowItem(string name)
{
borrowers.Add(name);
libraryItem.NumCopies--;
}
public void ReturnItem(string name)
{
borrowers.Remove(name);
libraryItem.NumCopies++;
}
public override void Display()
{
base.Display();
foreach(string borrower in borrowers)
{
Console.WriteLine($"빌려간 사람: {borrower}");
}
}
}
#endregion
}
//하단에서 사용될 공통 인터페이스를 제공, Facade는 상위단계의 인터페이스를 제공하여 하위단계에서 쓰기 쉽게 함
namespace Facade
{
#region 구조
/// <summary>
///
/// Facade (MortgageApplication) : 요청에 응답하는 하위 시스템 정보를 들고 있음, 클라이언트의 요청에 응답하는 대리자가 있음
/// Subsystem classes (Bank, Credit, Loan) : 하위단계 기능을 부여함, Facade객체로부터 행동을 전달받음, facade의 정보가 없고 해당참조도 없음
/// </summary>
class FacadeStructuralMain
{
static void Main()
{
Facade facade = new Facade();
facade.MethodA();
facade.MethodB();
Console.ReadKey();
}
}
class SubSystemOne
{
public void MethodOne()
{
Console.WriteLine("서브 시스템 1 함수");
}
}
class SubSystemTwo
{
public void MethodTwo()
{
Console.WriteLine("서브 시스템 2 함수");
}
}
class SubSystemThree
{
public void MethodThree()
{
Console.WriteLine("서브 시스템 3 함수");
}
}
class SubSystemFour
{
public void MethodFour()
{
Console.WriteLine("서브 시스템 4 함수");
}
}
class Facade
{
SubSystemOne one;
SubSystemTwo two;
SubSystemThree three;
SubSystemFour four;
public Facade()
{
one = new SubSystemOne();
two = new SubSystemTwo();
three = new SubSystemThree();
four = new SubSystemFour();
}
public void MethodA()
{
Console.WriteLine("\nMethodA()---------");
one.MethodOne();
two.MethodTwo();
four.MethodFour();
}
public void MethodB()
{
Console.WriteLine("\nMethodB()---------");
two.MethodTwo();
three.MethodThree();
}
}
#endregion
#region 예시
class FacadeRealMain
{
static void Main()
{
Mortgage mortgage = new Mortgage();
Customer customer = new Customer("Ann McKinsey");
bool eligible = mortgage.IsEligible(customer, 125000);
Console.WriteLine(("\n" + customer.Name + "has been" + (eligible ? "Approved" : "Rejected")));
Console.ReadKey();
}
}
class Bank
{
public bool HasSufficientSavings(Customer c, int amount)
{
Console.WriteLine("Check bank for " + c.Name);
return true;
}
}
class Credit
{
public bool HasGoodCredit(Customer c)
{
Console.WriteLine("Check credit for " + c.Name);
return true;
}
}
class Loan
{
public bool HasNoBadLoans(Customer c)
{
Console.WriteLine("Check loans for " + c.Name);
return true;
}
}
class Customer
{
string name;
public Customer(string name)
{
this.name = name;
}
public string Name
{
get { return name; }
}
}
class Mortgage
{
Bank bank = new Bank();
Loan loan = new Loan();
Credit credit = new Credit();
public bool IsEligible(Customer cust, int amount)
{
Console.WriteLine($"{cust.Name} applies for {amount:C} loan\n");
bool eligibile = true;
if(!bank.HasSufficientSavings(cust, amount))
{
eligibile = false;
}
else if (!loan.HasNoBadLoans(cust))
{
eligibile = false;
}
else if (!credit.HasGoodCredit(cust))
{
eligibile = false;
}
return eligibile;
}
}
#endregion
}
//많은 숫자의 잘 정리된 오브젝트를 효율적으로 공유하는 방법
namespace Flyweight
{
#region 구조
/// <summary>
/// Flyweight (Character) : flyweight들을 통해 전달받고 행동하는 상태들을 결정하는 인터페이스 내장
/// ConcreteFlyweight (CharacterA, CharacterB,...CharacterZ) : Flyweight의 인터페이스와 기본적인 상태를 포함, 해당객체는 공유 가능하고 어느 상태라도 ConcreteFlyweight의 객체의 상태와 무관해야 함
/// UnsharedConcreteFlyweight (not used) : Flyweight의 모든 하위 클래스가 꼭 공유가능한 상태는 아니어도 됨, Flyweight의 인터페이스는 공유 가능하나 반드시 공유가능한 상태일 필요는 없음
/// 공유하지 않는 오브젝트는 ConcreteFlyweight를 하위 클래스에 두고 있음
/// FlyweightFactory (CharacterFactory) : flyweight 객체 생성, 관리 담당, flyweight를 공유, client가 flyweight를 요청하면 FlyweightFactory객체를 지정 혹은 없으면 생성함
/// Client (FlyweightApp) : flyweight들의 참조를 유지, flyweight의 기본 상태를 계산, 가지고 있음
/// </summary>
class FlyweightStructuralMain
{
static void Main()
{
int extrinsicstate = 22;
FlyweightFactory factory = new FlyweightFactory();
Flyweight fx = factory.GetFlyweight("X");
fx.Operation(--extrinsicstate);
Flyweight fy = factory.GetFlyweight("Y");
fy.Operation(--extrinsicstate);
Flyweight fz = factory.GetFlyweight("Z");
fz.Operation(--extrinsicstate);
UnsharedConcreteFlyweight fu = new UnsharedConcreteFlyweight();
fu.Operation(--extrinsicstate);
Console.ReadKey();
}