Cvičenie 4
Singleton, Observer, Strategy, Decorator
Cvičenie 4
Od tohto týždňa sa vyžaduje pravidelná práca na projekte. V rámci vášho GitHub repozitára potrebujete pravidelne commitovať ucelené časti kódu. Minimálne 2 commity týždenne (môže byť aj v rámci jedného dňa). Môžete vynechať maximálne jeden týždeň počas semestra aby ste mali možnosť dosiahnúť plný počet bodov. Rátajú sa len commity, ktoré sú vytvorené v rámci repozitára projektu, ktorý vám bol zaslaný cvičiacim.
Úlohy
- Začnite pracovať na projekte - môžete začať vytvárať základnú štruktúru projektu na základe špecifikácie.
- Môžete si vytvoriť základ (inicializáciu) testovacieho prostredia. (Postup je v rámci Prednášky 5 16:00 minúta)
- Konzultujte so svojím cvičiacim prácu na projekte
Java Úlohy
Download the skeleton files
Task 8 — Potions, Inventory & Error Handling
Decorator Pattern, Custom Exceptions, Generics & Lambda Expressions
Your RPG world from previous tasks is growing. Characters can fight, equip weapons, and level up — but what happens when a warrior drinks a healing potion mid-battle? What if someone tries to stuff a 51st item into a backpack that only holds 50? And what if a player attempts to heal a character that's already dead?
In this task you will extend the RPG system with four new concepts that are central to real-world Java development. You are given the core character classes fully implemented (from Task 6). Everything else you build from scratch — the description below guides you through the problems you need to solve and the design approaches you should use.
Important: Do not change method signatures or access modifiers in the provided files.
What you must implement
Naming conventions
All your classes should be in package org.jikvict.tasks.exposed. Choose class names that
clearly describe their purpose — the tests will look for names that follow standard Java
conventions and match the concepts described above (e.g., a class implementing the decorator
for healing boost should be named HealingBoostDecorator).
The exception classes should be named after the condition they represent: InvalidPotionException,
InventoryFullException, CharacterDeadException.
The base potion class should be named BasePotion. The abstract decorator should be named
PotionDecorator. The duration-extending decorator should be named DurationExtenderDecorator.
The generic inventory class should be named Inventory.
Design hints
- The abstract decorator should have a protected field for the wrapped potion, so concrete decorators can access it directly.
- Think carefully about how
apply()works in decorators — the healing boost decorator needs to both delegate to the wrapped potion and add its own extra healing. - The
Inventoryclass has nothing potion-specific in it. It works with any typeT. findAllandfindFirstshould use theItemFilter<T>interface, notjava.util.function.Predicate. This is intentional — you should understand how functional interfaces work, not just use the standard library ones.- Your exceptions are checked — this means methods that throw them must declare it in their signature, and callers must handle them.
Submission
Take your whole project, remove unnecessary files (like .idea folder or build folder) and zip it.
The final zip file should contain the default-structure folder at the root.