diff --git a/README.md b/README.md index 9bc52b6..44b0b2e 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ To get started, add this Maven dependency: ## Scopes -[Service Locators](docs/Frequently_Asked_Questions.md#not-your-mothers-service-locator) are registries +[Service Locators](docs/frequently_asked_questions.md#not-your-mothers-service-locator) are registries that contain one or more *values*. Values can be bound to one or more *scopes*. A scope is the context within which a value is defined. diff --git a/core/src/main/java/com/github/cowwoc/pouch/core/Scope.java b/core/src/main/java/com/github/cowwoc/pouch/core/Scope.java new file mode 100644 index 0000000..29674aa --- /dev/null +++ b/core/src/main/java/com/github/cowwoc/pouch/core/Scope.java @@ -0,0 +1,33 @@ +package com.github.cowwoc.pouch.core; + +/** + * The lifespan of one or more variables. + *

+ * Child scopes must call {@link #addChild(Scope)} at the end of their constructor and + * {@link #removeChild(Scope)} at the end of their {@link #close()} method. + */ +public interface Scope extends AutoCloseable +{ + /** + * Adds a child scope. + * + * @param child the child scope + * @throws IllegalStateException if the scope is closed + */ + void addChild(Scope child); + + /** + * Removes a child scope. + * + * @param child the child scope + */ + void removeChild(Scope child); + + /** + * @return {@code true} if the scope is closed + */ + boolean isClosed(); + + @Override + void close(); +} \ No newline at end of file diff --git a/docs/Changelog.md b/docs/changelog.md similarity index 95% rename from docs/Changelog.md rename to docs/changelog.md index a3087c3..bbb47a5 100644 --- a/docs/Changelog.md +++ b/docs/changelog.md @@ -1,6 +1,10 @@ Minor updates involving cosmetic changes have been omitted from this list. See [commits](../../commits/master) for a full list. +## Version 5.3 - 2024/12/29 + +* Added a common definition of a `Scope`. + ## Version 5.2 - 2024/12/12 * Bugfix: [Fail on WrappedCheckedException validation before calling super](https://github.com/cowwoc/pouch/pull/9) by [Berk Koprucu](https://github.com/bkoprucu) diff --git a/docs/Frequently_Asked_Questions.md b/docs/frequently_asked_questions.md similarity index 100% rename from docs/Frequently_Asked_Questions.md rename to docs/frequently_asked_questions.md