dddsample-core中model的作用是什么
dddsample-core中model的作用是什么,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
高阳网站建设公司创新互联,高阳网站设计制作,有大型网站制作公司丰富经验。已为高阳1000+提供企业网站建设服务。企业网站搭建\成都外贸网站建设要多少钱,请找那个售后服务好的高阳做网站的公司定做!
Entity
public interface Entity{ /** * Entities compare by identity, not by attributes. * * @param other The other entity. * @return true if the identities are the same, regardless of other attributes. */ boolean sameIdentityAs(T other); }
Entity接口定义了sameIdentityAs方法
ValueObject
public interface ValueObjectextends Serializable { /** * Value objects compare by the values of their attributes, they don't have an identity. * * @param other The other value object. * @return true
if the given value object's and this value object's attributes are the same. */ boolean sameValueAs(T other); }
ValueObject接口定义了sameValueAs方法
TrackingId
public final class TrackingId implements ValueObject{ private String id; /** * Constructor. * * @param id Id string. */ public TrackingId(final String id) { Validate.notNull(id); this.id = id; } /** * @return String representation of this tracking id. */ public String idString() { return id; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; TrackingId other = (TrackingId) o; return sameValueAs(other); } @Override public int hashCode() { return id.hashCode(); } @Override public boolean sameValueAs(TrackingId other) { return other != null && this.id.equals(other.id); } @Override public String toString() { return id; } TrackingId() { // Needed by Hibernate } }
TrackingId实现了ValueObject接口,sameValueAs方法通过equals方法判断
Type
public enum Type implements ValueObject{ LOAD(true), UNLOAD(true), RECEIVE(false), CLAIM(false), CUSTOMS(false); private final boolean voyageRequired; /** * Private enum constructor. * * @param voyageRequired whether or not a voyage is associated with this event type */ private Type(final boolean voyageRequired) { this.voyageRequired = voyageRequired; } /** * @return True if a voyage association is required for this event type. */ public boolean requiresVoyage() { return voyageRequired; } /** * @return True if a voyage association is prohibited for this event type. */ public boolean prohibitsVoyage() { return !requiresVoyage(); } @Override public boolean sameValueAs(Type other) { return other != null && this.equals(other); } }
Type枚举实现了ValueObject接口,其sameValueAs方法通过equals判断
DomainEvent
public interface DomainEvent{ /** * @param other The other domain event. * @return true
if the given domain event and this event are regarded as being the same event. */ boolean sameEventAs(T other); }
DomainEvent接口定义了sameEventAs方法
小结
dddsample-core定义了Entity、ValueObject、DomainEvent接口,它们分别定义了sameIdentityAs、sameValueAs、sameEventAs方法。
看完上述内容,你们掌握dddsample-core中model的作用是什么的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!
网站栏目:dddsample-core中model的作用是什么
网页地址:http://myzitong.com/article/jjcdid.html