File tree Expand file tree Collapse file tree 3 files changed +74
-3
lines changed
Expand file tree Collapse file tree 3 files changed +74
-3
lines changed Original file line number Diff line number Diff line change 3939
4040 - name : Build C# project
4141 run : |
42- dotnet new console -o csharp_app --force
43- cp assignment_4/csharp/*.cs csharp_app/
44- dotnet build csharp_app -o assignment_4/output_csharp
42+ dotnet new console -o assignment_4/csharp --force
43+ dotnet build assignment_4/csharp -o assignment_4/output_csharp
4544
4645 - name : Build Kotlin project
4746 run : |
Original file line number Diff line number Diff line change 1+ using System ;
2+
3+ class Calculator
4+ {
5+ private double result = 0 ;
6+
7+ public Calculator Add ( double value )
8+ {
9+ result += value ;
10+ return this ; // 자기 자신 반환
11+ }
12+
13+ public Calculator Subtract ( double value )
14+ {
15+ result -= value ;
16+ return this ;
17+ }
18+
19+ public Calculator Multiply ( double value )
20+ {
21+ result *= value ;
22+ return this ;
23+ }
24+
25+ public Calculator Divide ( double value )
26+ {
27+ if ( value != 0 )
28+ {
29+ result /= value ;
30+ }
31+ return this ;
32+ }
33+
34+ public double GetResult ( )
35+ {
36+ return result ;
37+ }
38+ }
39+
Original file line number Diff line number Diff line change 1+ using System ;
2+
3+ class Program
4+ {
5+ static void Main ( string [ ] args )
6+ {
7+ Console . WriteLine ( "=== Adapter Pattern ===" ) ;
8+ ExternalClass external = new ExternalClass ( ) ;
9+ IInternal adapter = new Adapter ( external ) ;
10+ Console . WriteLine ( adapter . Fetch ( ) ) ;
11+
12+ Console . WriteLine ( "\n === Decorator Pattern ===" ) ;
13+ Coffee basic = new BasicCoffee ( ) ;
14+ Coffee milk = new MilkDecorator ( basic ) ;
15+ Coffee sugarMilk = new SugarDecorator ( milk ) ;
16+ Console . WriteLine ( $ "총 커피 가격: { sugarMilk . Cost ( ) } ") ;
17+
18+ Console . WriteLine ( "\n === Facade Pattern ===" ) ;
19+ Computer computer = new Computer ( ) ;
20+ computer . Boot ( ) ;
21+
22+ Console . WriteLine ( "\n === Factory Method Pattern ===" ) ;
23+ Animal dog = AnimalFactory . CreateAnimal ( "dog" ) ;
24+ Animal cat = AnimalFactory . CreateAnimal ( "cat" ) ;
25+ Console . WriteLine ( $ "Dog says: { dog ? . Speak ( ) } ") ;
26+ Console . WriteLine ( $ "Cat says: { cat ? . Speak ( ) } ") ;
27+
28+ Console . WriteLine ( "\n === Method Chaining Pattern ===" ) ;
29+ Calculator calc = new Calculator ( ) ;
30+ double result = calc . Add ( 10 ) . Subtract ( 2 ) . Multiply ( 3 ) . Divide ( 4 ) . GetResult ( ) ;
31+ Console . WriteLine ( $ "계산 결과: { result } ") ;
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments