{"id":25943561,"url":"https://github.com/julianamancera/labassign2_state-pattern","last_synced_at":"2025-07-07T08:08:53.380Z","repository":{"id":277469208,"uuid":"932513525","full_name":"JulianaMancera/LabAssign2_State-Pattern","owner":"JulianaMancera","description":"Software Engineering 2 - State Pattern: Laboratory Assignment 2","archived":false,"fork":false,"pushed_at":"2025-02-25T04:11:23.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T04:28:49.567Z","etag":null,"topics":["software-engineering","state-pattern","vending-machine"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JulianaMancera.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-14T03:10:15.000Z","updated_at":"2025-02-25T04:11:26.000Z","dependencies_parsed_at":"2025-02-14T04:39:39.034Z","dependency_job_id":null,"html_url":"https://github.com/JulianaMancera/LabAssign2_State-Pattern","commit_stats":null,"previous_names":["julianamancera/labassign2_state-pattern"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JulianaMancera%2FLabAssign2_State-Pattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JulianaMancera%2FLabAssign2_State-Pattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JulianaMancera%2FLabAssign2_State-Pattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JulianaMancera%2FLabAssign2_State-Pattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JulianaMancera","download_url":"https://codeload.github.com/JulianaMancera/LabAssign2_State-Pattern/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241801255,"owners_count":20022396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["software-engineering","state-pattern","vending-machine"],"created_at":"2025-03-04T07:17:38.833Z","updated_at":"2025-03-04T07:17:39.421Z","avatar_url":"https://github.com/JulianaMancera.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LabAssign2_State-Pattern\n\n### Problem:\n\u0026emsp;\u0026emsp;A vending machine needs to manage different states, including `\"Idle\"`, `\"ItemSelected\"`, `\"Dispensing\"`, and `\"OutOfOrder\"`. Each state has specific rules and restrictions regarding allowed operations, and the vending machine has associated attributes like item inventory and balance. \n\n### Requirements:\n**1. Idle State:**\n- Allow item selection.\n- Disallow dispensing items and inserting coins.\n  \n**2. ItemSelected State:**\n- Allow inserting coins and dispensing items.\n- Disallow item selection\n  \n**3. Dispensing State:**\n- Allow no operations.\n- Automatically transition back to the \"Idle\" state after dispensing is complete.\n\n**4. OutOfOrder State:**\n- Disallow all operations.\n\n**Current System:** The system currently relies on conditional statements within the VendingMachine class to check the machine state and determine valid actions. This approach becomes cumbersome and error-prone as the number of states and their associated logic grows. \u003cbr\u003e\n\n### Implement the State Pattern to improve code maintainability and flexibility:\n\n**1. Define VendingMachine States:**\n- Create *separate classes* representing different machine states: `IdleState`, `ItemSelectedState`, `DispensingState`, and `OutOfOrderState`.\n\n**2. Implement State Interface:**\n- Define an *interface* `VendingMachineState` with methods for common actions like `selectItem`, `insertCoin`, `dispenseItem`, and `setOutOfOrder`.\n\n**3. Implement State Behaviors:**\n- Each concrete state class implements the `VendingMachineState` interface, providing specific behavior for its respective state. For example, the `IdleState` class would **allow item selection**, while the `OutOfOrderState `**wouldn't allow any operations**.\n\n**4. Update VendingMachine Class:**\n- Include attributes for item inventory and balance.\n- Remove state-specific logic from the `VendingMachine` class.\n- Introduce a reference to the current `VendingMachineState` object.\n- Delegate actions like `selectItem`, `insertCoin`, `dispenseItem`, and `setOutOfOrder` to the current state object through its corresponding methods.\n\n## UML Diagram\n![Vending Machine](https://github.com/user-attachments/assets/61f55e15-9c05-4f26-a7f5-02b8381e3484)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulianamancera%2Flabassign2_state-pattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjulianamancera%2Flabassign2_state-pattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulianamancera%2Flabassign2_state-pattern/lists"}