Skip to content

Commit

Permalink
feat: removed _bank field from Factories
Browse files Browse the repository at this point in the history
  • Loading branch information
lievvl committed Nov 27, 2021
1 parent 270012d commit b4be591
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 34 deletions.
3 changes: 1 addition & 2 deletions Banks/Entities/Bank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public void Inform(string message)

public void SetAccountCreator(IFactory accountCreator)
{
accountCreator.AttachBank(this);
_currentCreator = accountCreator;
}

Expand All @@ -121,7 +120,7 @@ public AbstractAccount CreateAccount(Client client)
throw new BankException("Client not at Bank!");
}

AbstractAccount account = _currentCreator.CreateAccount(client);
AbstractAccount account = _currentCreator.CreateAccount(this, client);
client.AddAccount(account);
return account;
}
Expand Down
13 changes: 3 additions & 10 deletions Banks/Entities/Factories/CreditAccountFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ namespace Banks.Entities.Factories
{
public class CreditAccountFactory : IFactory
{
private Bank _bank;

public AbstractAccount CreateAccount(Client client)
public AbstractAccount CreateAccount(Bank bank, Client client)
{
if (client == null)
{
Expand All @@ -18,13 +16,8 @@ public AbstractAccount CreateAccount(Client client)

return new CreditAccount(
client,
DateTime.Today.AddYears(_bank.YearsLiveOfAccounts),
_bank.CreditCommission);
}

public void AttachBank(Bank bank)
{
_bank = bank;
DateTime.Today.AddYears(bank.YearsLiveOfAccounts),
bank.CreditCommission);
}
}
}
13 changes: 3 additions & 10 deletions Banks/Entities/Factories/DebitAccountFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ namespace Banks.Entities.Factories
{
public class DebitAccountFactory : IFactory
{
private Bank _bank;

public void AttachBank(Bank bank)
{
_bank = bank;
}

public AbstractAccount CreateAccount(Client client)
public AbstractAccount CreateAccount(Bank bank, Client client)
{
if (client == null)
{
Expand All @@ -23,8 +16,8 @@ public AbstractAccount CreateAccount(Client client)

return new DebitAccount(
client,
DateTime.Today.AddYears(_bank.YearsLiveOfAccounts),
_bank.DebitInterestRate);
DateTime.Today.AddYears(bank.YearsLiveOfAccounts),
bank.DebitInterestRate);
}
}
}
13 changes: 3 additions & 10 deletions Banks/Entities/Factories/DepositAccountFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ namespace Banks.Entities.Factories
{
public class DepositAccountFactory : IFactory
{
private Bank _bank;

public void AttachBank(Bank bank)
{
_bank = bank;
}

public AbstractAccount CreateAccount(Client client)
public AbstractAccount CreateAccount(Bank bank, Client client)
{
if (client == null)
{
Expand All @@ -23,8 +16,8 @@ public AbstractAccount CreateAccount(Client client)

return new DepositAccount(
client,
DateTime.Today.AddYears(_bank.YearsLiveOfAccounts),
_bank.DepositHandler);
DateTime.Today.AddYears(bank.YearsLiveOfAccounts),
bank.DepositHandler);
}
}
}
3 changes: 1 addition & 2 deletions Banks/Services/IFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace Banks.Services
{
public interface IFactory
{
void AttachBank(Bank bank);
AbstractAccount CreateAccount(Client client);
AbstractAccount CreateAccount(Bank bank, Client client);
}
}

0 comments on commit b4be591

Please sign in to comment.