Skip to content

velizartodorov/VendingMachine

Repository files navigation

Vending Machine

Kotlin Version Build Tests

Building a vending machine in Kotlin because ... why not? 🙂

How to start? 🤔

  1. Make sure you have azul-13-sdk installed for Kotlin.
  2. Go to Main.kt and run the fun main() function.

Implementation 🔧

Functionality ✨

The vending machine works with a list of coins and can also return change. 🧙‍

For now, this basic implementation supports the following types of drinks:

  • Americano, Café Au Lait, Cappuccino, Cortado, Decaf, Espresso, Flat White, Iced Coffee, Irish Coffee, Latte, Macchiato, Mocha, Tea, Water

Architecture ⚙️

State pattern

The vending machine uses State Pattern and has several states - Idle, Running, Paused and Stopped and the transition goes as follows:

stateDiagram-v2
    Idle --> Running : start()
    Running --> Paused : pause()
    Paused --> Running : start()
    Paused --> Stopped : stop()
    Running --> Stopped : stop()
    Stopped --> Running : start()
Loading

Choice of drink 🍶 and container 📥📤

The choice of a drink and container is based on the Factory Pattern. All the drinks and containers implement the sealed interfaces Drink and Container respectively, and implement them. With the help of sealed interfaces in Kotlin, we can avoid the use of pattern matching/switch/if...else statements and can autoload new implementations.

For now, there are a few containers - water, beans, tea, milk, and sugar. When a certain container is chosen, the amount in the container decreases. If the container is empty, an exception is thrown to notify the user.

Contribution strategy 🌿

The work is being done directly on the main branch. It's a hobby project, so nothing sophisticated is planned (for now). 😉 In the Git messages you can find the following emojis, meaning:

Emoji Action
🔨 refactoring
feature
🐛 bug fixed
📚 update README.md
update tests
🚀 update building scripts

CI/CD 🚀

When a new commit is pushed, a GitHub Actions pipeline is triggered. This is acquired by the build.yml and tests.yml files. Example:

Releases

No releases published

Packages

No packages published

Languages