Hi community
I'm trying to implement the annotation @Value in my application to use the
"Value Objects" as defined in the concept of DDD .
I had no success : How I can set my class as a genuine Custom Value Type?
so that it can be used in the entities that require it.
I want to create the classic VO : "Contact" which consists of the following
properties ( in my case) :
Address, Telephone and Email.
@Value ( semanticsProviderName = "
ContactValueSemanticsProvider.class " )
public class Contact {
/ *
/ Need to the builder?
/
/ Public Contact ( String a, String t , String e) {
/ This.address = a;
/ This.telephone = t;
/ This.email = e ;
/ }
/
/ *
private String address ;
public String getAddress ( ) {
return address ;
}
public void setAddress (String address) {
this.address = address ;
}
private String telephone ;
getTelephone public String ( ) {
return telephone ;
}
public void setTelephone (String telephone) {
this.telephone = telephone ;
}
private String email ;
getEmail public String ( ) {
return email ;
}
public void setEmail (String email ) {
this.email = email ;
}
}
where ContactValueSemanticsProvider.class :
public final class ContactValueSemanticsProvider
extends AbstractValueSemanticsProvider <Conctact> {}
Then I wonder if the entity would have to have an attribute :
private Contact contact ;
public GetContact ( ) {
return contact ;
}
Finally in the service when I creating the entity object :
SomeEntity public newEntity (
@ Optional
@ Named ( " Address" ) String address,
@ Optional
@ Named ( " Telephone" ) String telephone ,
@ Optional
@ Named ( " email " ) String email
) {
final Contact contact
/ / The correct way to instantiate is THROUGH
newTransientInstance ( Contact.class ) ?
pourContacter (contact) ;
@ Hidden
SomeEntity public pourContacter ( ) (
Final Contact Contact
) {
SomeEntity end someEntity = newTransientInstance ( SomeEntity.class
) ;
someEntitity.setContact (contact) ;
persistIfNotAlready ( someEntity ) ;
someEntity return ;
}
It is the right way? or the way to work with the Value Object in ISIS is
another?
I welcome your suggestions
Thank you very much as always for your attention
Cheers !
Ezequiel