本篇文章給大家分享的是有關(guān)dddsample-core中Specification有什么用,小編覺得挺實用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
“專業(yè)、務(wù)實、高效、創(chuàng)新、把客戶的事當(dāng)成自己的事”是我們每一個人一直以來堅持追求的企業(yè)文化。 創(chuàng)新互聯(lián)是您可以信賴的網(wǎng)站建設(shè)服務(wù)商、專業(yè)的互聯(lián)網(wǎng)服務(wù)提供商! 專注于網(wǎng)站設(shè)計、成都網(wǎng)站制作、軟件開發(fā)、設(shè)計服務(wù)業(yè)務(wù)。我們始終堅持以客戶需求為導(dǎo)向,結(jié)合用戶體驗與視覺傳達(dá),提供有針對性的項目解決方案,提供專業(yè)性的建議,創(chuàng)新互聯(lián)建站將不斷地超越自我,追逐市場,引領(lǐng)市場!
public interface Specification<T> { /** * Check if {@code t} is satisfied by the specification. * * @param t Object to test. * @return {@code true} if {@code t} satisfies the specification. */ boolean isSatisfiedBy(T t); /** * Create a new specification that is the AND operation of {@code this} specification and another specification. * @param specification Specification to AND. * @return A new specification. */ Specification<T> and(Specification<T> specification); /** * Create a new specification that is the OR operation of {@code this} specification and another specification. * @param specification Specification to OR. * @return A new specification. */ Specification<T> or(Specification<T> specification); /** * Create a new specification that is the NOT operation of {@code this} specification. * @param specification Specification to NOT. * @return A new specification. */ Specification<T> not(Specification<T> specification); }
Specification接口定義了isSatisfiedBy、and、or、not方法
/** * Abstract base implementation of composite {@link Specification} with default * implementations for {@code and}, {@code or} and {@code not}. */ public abstract class AbstractSpecification<T> implements Specification<T> { /** * {@inheritDoc} */ public abstract boolean isSatisfiedBy(T t); /** * {@inheritDoc} */ public Specification<T> and(final Specification<T> specification) { return new AndSpecification<T>(this, specification); } /** * {@inheritDoc} */ public Specification<T> or(final Specification<T> specification) { return new OrSpecification<T>(this, specification); } /** * {@inheritDoc} */ public Specification<T> not(final Specification<T> specification) { return new NotSpecification<T>(specification); } }
AbstractSpecification聲明實現(xiàn)Specification,它實現(xiàn)了and、or、not方法
public class AndSpecification<T> extends AbstractSpecification<T> { private Specification<T> spec1; private Specification<T> spec2; /** * Create a new AND specification based on two other spec. * * @param spec1 Specification one. * @param spec2 Specification two. */ public AndSpecification(final Specification<T> spec1, final Specification<T> spec2) { this.spec1 = spec1; this.spec2 = spec2; } /** * {@inheritDoc} */ public boolean isSatisfiedBy(final T t) { return spec1.isSatisfiedBy(t) && spec2.isSatisfiedBy(t); } }
AndSpecification繼承了AbstractSpecification,它定義了spec1、spec2屬性,其isSatisfiedBy返回的是spec1.isSatisfiedBy(t) && spec2.isSatisfiedBy(t)
public class OrSpecification<T> extends AbstractSpecification<T> { private Specification<T> spec1; private Specification<T> spec2; /** * Create a new OR specification based on two other spec. * * @param spec1 Specification one. * @param spec2 Specification two. */ public OrSpecification(final Specification<T> spec1, final Specification<T> spec2) { this.spec1 = spec1; this.spec2 = spec2; } /** * {@inheritDoc} */ public boolean isSatisfiedBy(final T t) { return spec1.isSatisfiedBy(t) || spec2.isSatisfiedBy(t); } }
OrSpecification繼承了AbstractSpecification,它定義了spec1、spec2屬性,其isSatisfiedBy返回的是spec1.isSatisfiedBy(t) || spec2.isSatisfiedBy(t)
public class NotSpecification<T> extends AbstractSpecification<T> { private Specification<T> spec1; /** * Create a new NOT specification based on another spec. * * @param spec1 Specification instance to not. */ public NotSpecification(final Specification<T> spec1) { this.spec1 = spec1; } /** * {@inheritDoc} */ public boolean isSatisfiedBy(final T t) { return !spec1.isSatisfiedBy(t); } }
NotSpecification繼承了AbstractSpecification,它定義了spec1屬性,其isSatisfiedBy返回的是!spec1.isSatisfiedBy(t)
dddsample-core的Specification接口定義了isSatisfiedBy、and、or、not方法;AndSpecification、OrSpecification、NotSpecification繼承了AbstractSpecification,實現(xiàn)了Specification接口。
以上就是dddsample-core中Specification有什么用,小編相信有部分知識點(diǎn)可能是我們?nèi)粘9ぷ鲿姷交蛴玫降?。希望你能通過這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
名稱欄目:dddsample-core中Specification有什么用
當(dāng)前URL:http://aaarwkj.com/article44/pegeee.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、網(wǎng)站設(shè)計公司、自適應(yīng)網(wǎng)站、虛擬主機(jī)、定制網(wǎng)站、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)