Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ATM extensibility by replacing fixed properties with a dynamic list #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sookim-1
Copy link
Contributor

@sookim-1 sookim-1 commented Feb 4, 2025

  • Read CONTRIBUTING.md
  • Only edited files inside source folder (IMPORTANT) and commited them with a meaningful message
  • Ran generate-playground.sh, no errors
  • Opened playground, it worked fine
  • Did not commit the changes caused by generate-playground.sh
  • Linked to and/or created issue
  • Added a description to PR

📌 Summary

This PR enhances the flexibility of the ATM class by replacing its fixed currency properties (hundred, fifty, twenty, ten) with a dynamic moneyPileList array.

🔍 Problem

  • The original ATM implementation had hardcoded properties for each denomination (hundred, fifty, twenty, ten).
  • Adding a new denomination required modifying the ATM class.
  • The withdrawal process was fixed to start from hundred, making it difficult to change the order dynamically.

✅ Solution

  • Introduced a moneyPileList array to hold MoneyPile instances.
  • ATM now starts the withdrawal process from the first element of moneyPileList, allowing for a flexible chain configuration.
  • Now, adding new denominations or modifying the withdrawal order requires no changes to the ATM class, improving scalability.

🛠 Changes

  • Replaced fixed hundred, fifty, twenty, ten properties with moneyPileList: [Withdrawing].
  • The withdrawal process starts from moneyPileList.first!, making it adaptable.

🔬 Example Usage

let five = MoneyPile(value: 5, quantity: 10, next: nil)
let ten = MoneyPile(value: 10, quantity: 6, next: five)
let twenty = MoneyPile(value: 20, quantity: 2, next: ten)
let atm = ATM(moneyPileList: [twenty, ten, five]) // Customizable order!
atm.withdraw(amount: 25) // Can withdraw using 1x20 + 1x5

🚀 Benefits

  • More maintainable: No need to modify ATM for new denominations.
  • More flexible: Users can configure withdrawal order dynamically.
  • Backward-compatible: Works with existing MoneyPile implementation.

Would love to hear any feedback! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant