MyDigitalHorse, object-oriented programming in PHP
○ Archived
An object-oriented PHP assessment: modelling a competition stable (riders, equines, events) with business rules enforced through exceptions, following SOLID.
Context
MyDigitalHorse is MyDigitalSchool’s object-oriented programming exam from autumn 2022. The brief describes a competition stable: a manager, riders, horses, ponies and Shetlands, and events to enter them in.
Around the same time, I ran another PHP experiment: a small web interface, bolted onto a WordPress install, for switching Git branches and merging from the browser using the git-php library.
Challenge
The assessment was about business rules more than display. A rider cannot have more than five equines, a horse cannot enter PoneyGames, the same equine cannot be entered twice in an event, and each event has a limited water capacity that must not be exceeded.
The grader had to be able to check everything by running the script once, and every check had to go through exceptions, following SOLID principles.
Approach
I built a class hierarchy (abstract Human and Animal, Rider, Manager, Equine and its categories, Capability, Event) organised by namespace. Equine IDs are generated using the required pattern, colours became dedicated classes and setters are private wherever possible. A commented test script with expected results walks through every case.
For the Git interface, I used git-php to list a repository’s branches, show the current one, switch between them and run a merge, with a configurable list of repository paths. That second project stayed at the experiment stage.
(04) — Results
Key figures- 70
- commits across both repositories
- 4
- business rules enforced by exceptions
- 3
- equine categories
- 2022
- year
