diff --git a/csharp-fp1/Application/AccountApplicationService.cs b/csharp-fp1/Application/AccountApplicationService.cs deleted file mode 100644 index aa36a03..0000000 --- a/csharp-fp1/Application/AccountApplicationService.cs +++ /dev/null @@ -1,17 +0,0 @@ -using CsharpFp1.Domain; - -namespace CsharpFp1.Application; - -public static class AccountApplicationService -{ - public static void WithdrawMoney(IAccountRepository repository, Guid accountId, decimal amount) - { - var account = - repository.GetById(new AccountId(accountId)) - ?? throw new InvalidOperationException("Account not found."); - - account.Withdraw(new Money(amount)); - - repository.Save(account); - } -} diff --git a/csharp-fp1/Program.cs b/csharp-fp1/Program.cs deleted file mode 100644 index 7724203..0000000 --- a/csharp-fp1/Program.cs +++ /dev/null @@ -1,25 +0,0 @@ -using CsharpFp1.Application; -using CsharpFp1.Domain; -using CsharpFp1.Infrastructure; - -namespace CsharpFp1; - -public class Program -{ - public static void Main() - { - Console.WriteLine("[csharp-fp1] Starting withdraw money demo..."); - - var repository = new InMemoryAccountRepository(); - - var accountId = Guid.NewGuid(); - Console.WriteLine($"[csharp-fp1] Seeding account {accountId} with opening balance 200.00"); - repository.Save(new Account(new AccountId(accountId), new Money(200m))); - - decimal amount = 100m; - Console.WriteLine($"[csharp-fp1] Executing withdrawal {amount:0.00} from account {accountId}"); - AccountApplicationService.WithdrawMoney(repository, accountId, amount); - - Console.WriteLine("[csharp-fp1] Demo completed."); - } -} diff --git a/csharp-fp2/Application/AccountApplicationService.cs b/csharp-fp2/Application/AccountApplicationService.cs deleted file mode 100644 index a943b30..0000000 --- a/csharp-fp2/Application/AccountApplicationService.cs +++ /dev/null @@ -1,17 +0,0 @@ -using CsharpFp2.Domain; - -namespace CsharpFp2.Application; - -public static class AccountApplicationService -{ - public static void WithdrawMoney(IAccountRepository repository, Guid accountId, decimal amount) - { - var account = - repository.GetById(accountId) - ?? throw new InvalidOperationException("Account not found."); - - account.Withdraw(new Money(amount)); - - repository.Save(account); - } -} diff --git a/csharp-fp2/Program.cs b/csharp-fp2/Program.cs deleted file mode 100644 index 0a29595..0000000 --- a/csharp-fp2/Program.cs +++ /dev/null @@ -1,27 +0,0 @@ -using CsharpFp2.Application; -using CsharpFp2.Domain; -using CsharpFp2.Infrastructure; - -namespace CsharpFp2; - -public class Program -{ - public static void Main() - { - Console.WriteLine("[csharp-fp2] Starting withdraw money demo..."); - - var repository = new InMemoryAccountRepository(); - - var accountId = Guid.NewGuid(); - Console.WriteLine($"[csharp-fp2] Seeding account {accountId} with opening balance 200.00"); - repository.Save(new Account(accountId, new Money(200m))); - - decimal amount = 100m; - Console.WriteLine( - $"[csharp-fp2] Executing withdrawal {amount:0.00} from account {accountId}" - ); - AccountApplicationService.WithdrawMoney(repository, accountId, amount); - - Console.WriteLine("[csharp-fp2] Demo completed."); - } -} diff --git a/csharp-oop-simplified1/Application/AccountApplicationService.cs b/csharp-oop-simplified1/Application/AccountApplicationService.cs new file mode 100644 index 0000000..b73f11c --- /dev/null +++ b/csharp-oop-simplified1/Application/AccountApplicationService.cs @@ -0,0 +1,24 @@ +using CsharpOopSimplified1.Domain; + +namespace CsharpOopSimplified1.Application; + +public static class AccountApplicationService +{ + public static void WithdrawMoney(IAccountRepository repository, Guid accountId, decimal amount) + { + var account = + repository.GetById(new AccountId(accountId)) + ?? throw new InvalidOperationException("Account not found."); + + Console.WriteLine($"[App] Account loaded. Current balance: {account.Balance.Amount:0.00}"); + Console.WriteLine($"[App] Executing withdrawal of {amount:0.00}..."); + + account.Withdraw(new Money(amount)); + + Console.WriteLine($"[App] Withdrawal applied. New balance: {account.Balance.Amount:0.00}"); + + repository.Save(account); + + Console.WriteLine("[App] Account persisted."); + } +} diff --git a/csharp-fp1/Domain/Account.cs b/csharp-oop-simplified1/Domain/Account.cs similarity index 96% rename from csharp-fp1/Domain/Account.cs rename to csharp-oop-simplified1/Domain/Account.cs index 2080baa..5a05a15 100644 --- a/csharp-fp1/Domain/Account.cs +++ b/csharp-oop-simplified1/Domain/Account.cs @@ -1,4 +1,4 @@ -namespace CsharpFp1.Domain; +namespace CsharpOopSimplified1.Domain; /// Domain entity / aggregate root representing a bank account public sealed class Account : AggregateRoot diff --git a/csharp-fp1/Domain/AccountId.cs b/csharp-oop-simplified1/Domain/AccountId.cs similarity index 71% rename from csharp-fp1/Domain/AccountId.cs rename to csharp-oop-simplified1/Domain/AccountId.cs index 49346f5..870f2b1 100644 --- a/csharp-fp1/Domain/AccountId.cs +++ b/csharp-oop-simplified1/Domain/AccountId.cs @@ -1,4 +1,4 @@ -namespace CsharpFp1.Domain; +namespace CsharpOopSimplified1.Domain; /// Value object used to wrap the aggregate identity public sealed record AccountId(Guid Value); diff --git a/csharp-fp1/Domain/AggregateRoot.cs b/csharp-oop-simplified1/Domain/AggregateRoot.cs similarity index 78% rename from csharp-fp1/Domain/AggregateRoot.cs rename to csharp-oop-simplified1/Domain/AggregateRoot.cs index b9979d1..333f56c 100644 --- a/csharp-fp1/Domain/AggregateRoot.cs +++ b/csharp-oop-simplified1/Domain/AggregateRoot.cs @@ -1,4 +1,4 @@ -namespace CsharpFp1.Domain; +namespace CsharpOopSimplified1.Domain; /// Conventional DDD base type for aggregates public abstract class AggregateRoot diff --git a/csharp-fp1/Domain/IAccountRepository.cs b/csharp-oop-simplified1/Domain/IAccountRepository.cs similarity index 81% rename from csharp-fp1/Domain/IAccountRepository.cs rename to csharp-oop-simplified1/Domain/IAccountRepository.cs index 28fda00..6af2337 100644 --- a/csharp-fp1/Domain/IAccountRepository.cs +++ b/csharp-oop-simplified1/Domain/IAccountRepository.cs @@ -1,4 +1,4 @@ -namespace CsharpFp1.Domain; +namespace CsharpOopSimplified1.Domain; /// Repository abstraction used to load and save accounts public interface IAccountRepository diff --git a/csharp-fp1/Domain/InsufficientBalanceException.cs b/csharp-oop-simplified1/Domain/InsufficientBalanceException.cs similarity index 93% rename from csharp-fp1/Domain/InsufficientBalanceException.cs rename to csharp-oop-simplified1/Domain/InsufficientBalanceException.cs index 08333ad..3147d34 100644 --- a/csharp-fp1/Domain/InsufficientBalanceException.cs +++ b/csharp-oop-simplified1/Domain/InsufficientBalanceException.cs @@ -1,4 +1,4 @@ -namespace CsharpFp1.Domain; +namespace CsharpOopSimplified1.Domain; /// Custom domain exception thrown when a withdrawal would cause the balance to go below zero public sealed class InsufficientBalanceException : InvalidOperationException diff --git a/csharp-fp2/Domain/Money.cs b/csharp-oop-simplified1/Domain/Money.cs similarity index 96% rename from csharp-fp2/Domain/Money.cs rename to csharp-oop-simplified1/Domain/Money.cs index 7c0daec..54a1ac6 100644 --- a/csharp-fp2/Domain/Money.cs +++ b/csharp-oop-simplified1/Domain/Money.cs @@ -1,4 +1,4 @@ -namespace CsharpFp2.Domain; +namespace CsharpOopSimplified1.Domain; /// Value object used to represent money and enforce simple invariants. /// Note that this implementation uses immutable patterns for the data diff --git a/csharp-fp1/Infrastructure/InMemoryAccountRepository.cs b/csharp-oop-simplified1/Infrastructure/InMemoryAccountRepository.cs similarity index 89% rename from csharp-fp1/Infrastructure/InMemoryAccountRepository.cs rename to csharp-oop-simplified1/Infrastructure/InMemoryAccountRepository.cs index 2c9da43..d002c0f 100644 --- a/csharp-fp1/Infrastructure/InMemoryAccountRepository.cs +++ b/csharp-oop-simplified1/Infrastructure/InMemoryAccountRepository.cs @@ -1,6 +1,6 @@ -using CsharpFp1.Domain; +using CsharpOopSimplified1.Domain; -namespace CsharpFp1.Infrastructure; +namespace CsharpOopSimplified1.Infrastructure; /// Simple in-memory repository for demonstration public class InMemoryAccountRepository : IAccountRepository diff --git a/csharp-oop-simplified1/Program.cs b/csharp-oop-simplified1/Program.cs new file mode 100644 index 0000000..1f40001 --- /dev/null +++ b/csharp-oop-simplified1/Program.cs @@ -0,0 +1,29 @@ +using CsharpOopSimplified1.Application; +using CsharpOopSimplified1.Domain; +using CsharpOopSimplified1.Infrastructure; + +namespace CsharpOopSimplified1; + +public class Program +{ + public static void Main() + { + Console.WriteLine("[csharp-oop-simplified1] Starting withdraw money demo..."); + + var repository = new InMemoryAccountRepository(); + + var accountId = Guid.NewGuid(); + Console.WriteLine( + $"[csharp-oop-simplified1] Seeding account {accountId} with opening balance 200.00" + ); + repository.Save(new Account(new AccountId(accountId), new Money(200m))); + + decimal amount = 100m; + Console.WriteLine( + $"[csharp-oop-simplified1] Executing withdrawal {amount:0.00} from account {accountId}" + ); + AccountApplicationService.WithdrawMoney(repository, accountId, amount); + + Console.WriteLine("[csharp-oop-simplified1] Demo completed."); + } +} diff --git a/csharp-fp1/csharp-fp1.csproj b/csharp-oop-simplified1/csharp-oop-simplified1.csproj similarity index 81% rename from csharp-fp1/csharp-fp1.csproj rename to csharp-oop-simplified1/csharp-oop-simplified1.csproj index 05f1c4c..d02ce62 100644 --- a/csharp-fp1/csharp-fp1.csproj +++ b/csharp-oop-simplified1/csharp-oop-simplified1.csproj @@ -2,7 +2,7 @@ Exe net10.0 - csharp_fp1 + CsharpOopSimplified1 enable enable diff --git a/csharp-oop-simplified2/Application/AccountApplicationService.cs b/csharp-oop-simplified2/Application/AccountApplicationService.cs new file mode 100644 index 0000000..3efda42 --- /dev/null +++ b/csharp-oop-simplified2/Application/AccountApplicationService.cs @@ -0,0 +1,24 @@ +using CsharpOopSimplified2.Domain; + +namespace CsharpOopSimplified2.Application; + +public static class AccountApplicationService +{ + public static void WithdrawMoney(IAccountRepository repository, Guid accountId, decimal amount) + { + var account = + repository.GetById(accountId) + ?? throw new InvalidOperationException("Account not found."); + + Console.WriteLine($"[App] Account loaded. Current balance: {account.Balance.Amount:0.00}"); + Console.WriteLine($"[App] Executing withdrawal of {amount:0.00}..."); + + account.Withdraw(new Money(amount)); + + Console.WriteLine($"[App] Withdrawal applied. New balance: {account.Balance.Amount:0.00}"); + + repository.Save(account); + + Console.WriteLine("[App] Account persisted."); + } +} diff --git a/csharp-fp2/Domain/Account.cs b/csharp-oop-simplified2/Domain/Account.cs similarity index 96% rename from csharp-fp2/Domain/Account.cs rename to csharp-oop-simplified2/Domain/Account.cs index 745f918..5a3e671 100644 --- a/csharp-fp2/Domain/Account.cs +++ b/csharp-oop-simplified2/Domain/Account.cs @@ -1,4 +1,4 @@ -namespace CsharpFp2.Domain; +namespace CsharpOopSimplified2.Domain; /// Domain entity / aggregate root representing a bank account public sealed class Account diff --git a/csharp-fp2/Domain/IAccountRepository.cs b/csharp-oop-simplified2/Domain/IAccountRepository.cs similarity index 80% rename from csharp-fp2/Domain/IAccountRepository.cs rename to csharp-oop-simplified2/Domain/IAccountRepository.cs index da5fc30..3425b46 100644 --- a/csharp-fp2/Domain/IAccountRepository.cs +++ b/csharp-oop-simplified2/Domain/IAccountRepository.cs @@ -1,4 +1,4 @@ -namespace CsharpFp2.Domain; +namespace CsharpOopSimplified2.Domain; /// Repository abstraction used to load and save accounts public interface IAccountRepository diff --git a/csharp-fp2/Domain/InsufficientBalanceException.cs b/csharp-oop-simplified2/Domain/InsufficientBalanceException.cs similarity index 93% rename from csharp-fp2/Domain/InsufficientBalanceException.cs rename to csharp-oop-simplified2/Domain/InsufficientBalanceException.cs index 13a436a..30658fa 100644 --- a/csharp-fp2/Domain/InsufficientBalanceException.cs +++ b/csharp-oop-simplified2/Domain/InsufficientBalanceException.cs @@ -1,4 +1,4 @@ -namespace CsharpFp2.Domain; +namespace CsharpOopSimplified2.Domain; /// Custom domain exception thrown when a withdrawal would cause the balance to go below zero public sealed class InsufficientBalanceException : InvalidOperationException diff --git a/csharp-fp1/Domain/Money.cs b/csharp-oop-simplified2/Domain/Money.cs similarity index 96% rename from csharp-fp1/Domain/Money.cs rename to csharp-oop-simplified2/Domain/Money.cs index 61f1c2f..2156789 100644 --- a/csharp-fp1/Domain/Money.cs +++ b/csharp-oop-simplified2/Domain/Money.cs @@ -1,4 +1,4 @@ -namespace CsharpFp1.Domain; +namespace CsharpOopSimplified2.Domain; /// Value object used to represent money and enforce simple invariants. /// Note that this implementation uses immutable patterns for the data diff --git a/csharp-fp2/Infrastructure/InMemoryAccountRepository.cs b/csharp-oop-simplified2/Infrastructure/InMemoryAccountRepository.cs similarity index 88% rename from csharp-fp2/Infrastructure/InMemoryAccountRepository.cs rename to csharp-oop-simplified2/Infrastructure/InMemoryAccountRepository.cs index 6638954..cd73b80 100644 --- a/csharp-fp2/Infrastructure/InMemoryAccountRepository.cs +++ b/csharp-oop-simplified2/Infrastructure/InMemoryAccountRepository.cs @@ -1,6 +1,6 @@ -using CsharpFp2.Domain; +using CsharpOopSimplified2.Domain; -namespace CsharpFp2.Infrastructure; +namespace CsharpOopSimplified2.Infrastructure; /// Simple in-memory repository for demonstration public class InMemoryAccountRepository : IAccountRepository diff --git a/csharp-oop-simplified2/Program.cs b/csharp-oop-simplified2/Program.cs new file mode 100644 index 0000000..2e6fee1 --- /dev/null +++ b/csharp-oop-simplified2/Program.cs @@ -0,0 +1,29 @@ +using CsharpOopSimplified2.Application; +using CsharpOopSimplified2.Domain; +using CsharpOopSimplified2.Infrastructure; + +namespace CsharpOopSimplified2; + +public class Program +{ + public static void Main() + { + Console.WriteLine("[csharp-oop-simplified2] Starting withdraw money demo..."); + + var repository = new InMemoryAccountRepository(); + + var accountId = Guid.NewGuid(); + Console.WriteLine( + $"[csharp-oop-simplified2] Seeding account {accountId} with opening balance 200.00" + ); + repository.Save(new Account(accountId, new Money(200m))); + + decimal amount = 100m; + Console.WriteLine( + $"[csharp-oop-simplified2] Executing withdrawal {amount:0.00} from account {accountId}" + ); + AccountApplicationService.WithdrawMoney(repository, accountId, amount); + + Console.WriteLine("[csharp-oop-simplified2] Demo completed."); + } +} diff --git a/csharp-fp2/csharp-fp2.csproj b/csharp-oop-simplified2/csharp-oop-simplified2.csproj similarity index 81% rename from csharp-fp2/csharp-fp2.csproj rename to csharp-oop-simplified2/csharp-oop-simplified2.csproj index 55a99b6..d8edbea 100644 --- a/csharp-fp2/csharp-fp2.csproj +++ b/csharp-oop-simplified2/csharp-oop-simplified2.csproj @@ -2,7 +2,7 @@ Exe net10.0 - csharp_fp2 + CsharpOopSimplified2 enable enable diff --git a/csharp.sln b/csharp.sln index c9a4104..bdbf68d 100644 --- a/csharp.sln +++ b/csharp.sln @@ -11,9 +11,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp-oop.Tests", "csharp- EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FP", "FP", "{89C53051-77F9-4C1C-ABE5-6D54AB398471}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp-fp1", "csharp-fp1\csharp-fp1.csproj", "{561BCA96-76DF-4A33-B767-4AD7CD3246B4}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp-oop-simplified1", "csharp-oop-simplified1\csharp-oop-simplified1.csproj", "{561BCA96-76DF-4A33-B767-4AD7CD3246B4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp-fp2", "csharp-fp2\csharp-fp2.csproj", "{7237398A-2E8B-4161-BA15-DB090395A1F2}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp-oop-simplified2", "csharp-oop-simplified2\csharp-oop-simplified2.csproj", "{7237398A-2E8B-4161-BA15-DB090395A1F2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -80,7 +80,7 @@ Global GlobalSection(NestedProjects) = preSolution {E00F4E4F-8D52-49CE-8754-ED8378A5278F} = {CEC0EC27-0CEC-90C6-CABA-E58AB278E4DA} {9FD0C8F4-A23B-4C68-A365-86E7EF5623D8} = {CEC0EC27-0CEC-90C6-CABA-E58AB278E4DA} - {561BCA96-76DF-4A33-B767-4AD7CD3246B4} = {89C53051-77F9-4C1C-ABE5-6D54AB398471} - {7237398A-2E8B-4161-BA15-DB090395A1F2} = {89C53051-77F9-4C1C-ABE5-6D54AB398471} + {561BCA96-76DF-4A33-B767-4AD7CD3246B4} = {CEC0EC27-0CEC-90C6-CABA-E58AB278E4DA} + {7237398A-2E8B-4161-BA15-DB090395A1F2} = {CEC0EC27-0CEC-90C6-CABA-E58AB278E4DA} EndGlobalSection EndGlobal