As the number of connected devices rapidly increases, largely thanks to uptake of IoT technologies, there is significant stimulus to enable opportunistic interactions between different systems that encounter each other at run time. However, this is complicated by diversity in IoT technologies and implementation details that are not known in advance. To achieve such unplanned interactions, we use the concept of a holon to represent a system's services and requirements at a high level. A holon is a self-describing system that appears as a whole when viewed from above whilst potentially comprising multiple subsystems when viewed from below. In order to realise this world view and facilitate opportunistic system interactions, we propose the idea of using ontologies to define and program a holon. Ontologies offer the ability to classify the concepts of a domain, and use this formalised knowledge to infer new knowledge through reasoning. In this paper, we design a holon ontology and associated code generation tools. We also explore a case study of how programming holons using this approach can aid an IoT system to self-describe and reason about other systems it encounters. As such, developers can develop system composition logic at a high-level without any preconceived notions about low-level implementation details.