Öffentliche APIs und Struktur
Entscheiden Sie, was Sie bereitstellen.
Öffentliche APIs und Struktur ist eine kostenlose Mojo Academy-Lektion auf CoddyKit. Dies ist Lektion 3 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Mojo Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Mojo Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
What You Show Matters
A good library is judged by its surface. Deciding what to expose shapes how easy your API is to use. 🚪
Your Public API
The functions and types other code is meant to call form your public API. It is the promise you keep to users.
Internals Stay Hidden
Helper code that supports your API but is not meant for callers is internal. Hiding it keeps your surface small.
Smaller Surface, Less Risk
The fewer names you expose, the easier the library is to learn and the more freely you can change internals later.
Re-export From __init__
A package's __init__.mojo can import key names so users reach them straight from the package, not deep files.
from .core import add, subtractA Clean Front Door
By gathering imports in __init__, you give callers one clear entry point instead of long, fragile module paths.
from mypkg import addHide the Layout
Users import from the package, not its files. That lets you rearrange inner modules without breaking their code.
Name Things Clearly
Public names should be self-explanatory. A clear, stable name is part of the contract you do not want to change.
Document the Surface
Add a docstring to each public function and type. Good docs tell callers how to use the API correctly.
fn add(a: Int, b: Int) -> Int:
"""Return the sum of a and b."""
return a + bStable Promises
Treat your public API as a contract. Changing it can break users, so keep it small and think before you grow it.
Design From Outside In
Picture how a caller wants to use your library first, then build the internals to serve that clean experience. 🎨
Quick Check
Let us think about keeping an API easy to maintain.
Recap
Expose a small, clear public API, re-export key names in __init__, hide internals, and document what you share. 🎯
Häufig gestellte Fragen
Ist die Lektion „Öffentliche APIs und Struktur“ kostenlos?
Ja — der vollständige Text von „Öffentliche APIs und Struktur“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Mojo Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Mojo Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Öffentliche APIs und Struktur“?
Entscheiden Sie, was Sie bereitstellen. Du übst Mojo Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Mojo Academy zu starten?
Keine Vorkenntnisse erforderlich. Mojo Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 3 von 4.
Wie lange dauert die Lektion „Öffentliche APIs und Struktur“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Mojo Academy-Lektion Code schreiben und ausführen?
Ja. Jede Mojo Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Module und Imports
- Ein .mojopkg erstellen
- Öffentliche APIs und Struktur
- Bewährte Projektstruktur