:tutorials:state-modeling refine snippets
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/33f8825e Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/33f8825e Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/33f8825e Branch: refs/heads/develop Commit: 33f8825eb79019ff48dd43aa14620db2634467fd Parents: ff1b7af Author: Paul Merlin <[email protected]> Authored: Mon May 15 09:16:51 2017 +0200 Committer: Paul Merlin <[email protected]> Committed: Mon May 15 09:16:51 2017 +0200 ---------------------------------------------------------------------- .../introduction/src/docs/state-modeling.txt | 6 +-- .../polygene/demo/intro/StateModelingDocs.java | 53 ++++++++------------ 2 files changed, 24 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/33f8825e/tutorials/introduction/src/docs/state-modeling.txt ---------------------------------------------------------------------- diff --git a/tutorials/introduction/src/docs/state-modeling.txt b/tutorials/introduction/src/docs/state-modeling.txt index c573863..dd44066 100644 --- a/tutorials/introduction/src/docs/state-modeling.txt +++ b/tutorials/introduction/src/docs/state-modeling.txt @@ -57,7 +57,7 @@ express is very explicit. To define a property you would have had to write a field and two accessors, and if you use interfaces then those accessors would have to be duplicated. -The EntityComposite base interface also includes an identity property for you, as that's an intrinsic feature of +The `HasIdentity` base interface also includes an identity property for you, as that's an intrinsic feature of Entities, so that's all taken care of. So if you speak about Entities in your domain discussions, each having Properties, then you can put that down in code pretty much as-is. @@ -114,8 +114,8 @@ tag=values Normally if you want a property to be immutable, meaning, you can set an initial value but not change it later, you would have to mark the Property as @Immutable. -But since NameValue extends ValueComposite, which itself is marked with @Immutable, this is implicit for all subtypes -of ValueComposite, and there's no way to "opt out" of it. +But since NameValue will be assembled as a ValueComposite, which itself is marked with @Immutable, this is implicit +for all ValueComposites, and there's no way to "opt out" of it. By introducing one more level in the state model you have created an easy way to access the name as a whole and hand it around the system, instead of as two separate properties. http://git-wip-us.apache.org/repos/asf/polygene-java/blob/33f8825e/tutorials/introduction/src/main/java/org/apache/polygene/demo/intro/StateModelingDocs.java ---------------------------------------------------------------------- diff --git a/tutorials/introduction/src/main/java/org/apache/polygene/demo/intro/StateModelingDocs.java b/tutorials/introduction/src/main/java/org/apache/polygene/demo/intro/StateModelingDocs.java index 80da494..ae8e7ee 100644 --- a/tutorials/introduction/src/main/java/org/apache/polygene/demo/intro/StateModelingDocs.java +++ b/tutorials/introduction/src/main/java/org/apache/polygene/demo/intro/StateModelingDocs.java @@ -25,6 +25,7 @@ import org.apache.polygene.api.common.Optional; import org.apache.polygene.api.common.UseDefaults; import org.apache.polygene.api.entity.Aggregated; import org.apache.polygene.api.entity.EntityComposite; +import org.apache.polygene.api.identity.HasIdentity; import org.apache.polygene.api.injection.scope.This; import org.apache.polygene.api.mixin.Mixins; import org.apache.polygene.api.property.Property; @@ -33,39 +34,34 @@ import org.apache.polygene.api.value.ValueComposite; public class StateModelingDocs { -// START SNIPPET: intro1 - interface PersonEntity - extends EntityComposite + // START SNIPPET: intro1 + interface PersonEntity extends HasIdentity { Property<String> givenName(); Property<String> surName(); } - -// END SNIPPET: intro1 + // END SNIPPET: intro1 static class Roles { -// START SNIPPET: roles + // START SNIPPET: roles interface Nameable { @UseDefaults Property<String> givenName(); @UseDefaults @Optional Property<String> surName(); } - interface PersonEntity - extends Nameable, EntityComposite - {} -// END SNIPPET: roles + interface PersonEntity extends Nameable, HasIdentity {} + // END SNIPPET: roles } static class Values { -// START SNIPPET: values + // START SNIPPET: values interface NameValue - extends ValueComposite { @UseDefaults Property<String> givenName(); @UseDefaults @Optional Property<String> surName(); @@ -75,19 +71,16 @@ public class StateModelingDocs { Property<NameValue> name(); } -// END SNIPPET: values + // END SNIPPET: values -// START SNIPPET: private - @Mixins(ListablePersonMixin.class) - interface PersonEntity - extends Listable, EntityComposite {} + // START SNIPPET: private + @Mixins( ListablePersonMixin.class ) + interface PersonEntity extends Listable, HasIdentity {} - interface PersonState - extends Nameable {} + interface PersonState extends Nameable {} - public class ListablePersonMixin - implements Listable + public class ListablePersonMixin implements Listable { @This PersonState person; @@ -103,17 +96,16 @@ public class StateModelingDocs interface Listable { - public String listName(); + String listName(); } -// END SNIPPET: private + // END SNIPPET: private } static class More { -// START SNIPPET: more - interface PersonEntity - extends EntityComposite + // START SNIPPET: more + interface PersonEntity extends HasIdentity { Association<PersonEntity> father(); @Optional Association<PersonEntity> spouse(); @@ -121,17 +113,14 @@ public class StateModelingDocs @Aggregated ManyAssociation<BookNoteEntity> favouriteBooks(); } - interface BookNoteEntity - extends EntityComposite + interface BookNoteEntity extends HasIdentity { Property<String> note(); Association<BookEntity> book(); } -// END SNIPPET: more - interface BookEntity - extends EntityComposite - {} + // END SNIPPET: more + interface BookEntity extends HasIdentity {} } }
