lundi 18 mai 2020

I need a better code or a suitable Design Pattern, please help me with this [closed]

I have code something like this, but I do not like to create Review Object using StringUtil.ifNull(-,-) in each setter or builder method as shown below. Can someone give me a better idea or a design/design pattern?

Review review = new Review()
                .reviewTitle(StringUtil.ifNull(reviewTitle, null))
                .reviewerName(StringUtil.ifNull(reviewerName, null))
                .rating(StringUtil.ifNull(reviewRating, null))
                .date(StringUtil.ifNull(reviewDate, null))
                .review(StringUtil.ifNull(reviewBody, null));


public class StringUtil {

 public static String ifNull(DomNode domNode, String returnObj) {
    if (Objects.nonNull(domNode)) {
      return domNode.getTextContent();
    }
    return returnObj;
  }
}

Thank You so much...

Aucun commentaire:

Enregistrer un commentaire