Skip to content

Commit 6da49ee

Browse files
committed
last
1 parent 6f8a4ed commit 6da49ee

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

.github/workflows/build-release.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ jobs:
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: |

assignment_4/csharp/methodchain.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+

assignment_4/csharp/program.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

0 commit comments

Comments
 (0)