I've just stuck with some really weird classes, which is the logic mixed.
< code> if (! RealTraffic.getPvkp () = null) {// entry point if (BeanUtils.isGuidEntity (realTraffic.getPvkp: the city code that generates a query to the database instance ())) {findParameters + = "and getGuid (" + staticTableName () + '.guidPvkp =' '+ realTraffic.getPvkp (). getGuid () +' 'or ( "+ staticTableName () +' .guidPvkpOut = '" + realTraffic.getPvkp () () + '' and "+ staticTableName () + '.requestType =" + RequestBean.TRANSIT_TYPE + ")."; if (companyType == CompanyBean.PP_TYPE & amp; & amp ;! realTraffic.isSkipOther ()) {/ / TODO - non-formation findParamete Rs + = "or (" + staticTableName () add + "KguidPvkpOut empty" + "and" + staticTableName () + '.requestType = "+ RequestBean.TRANSIT_TYPE +") ";} searches parameter + =") " ;} then Else does {// territorial Department, (BeanUtils.isGuidEntity (realTraffic.getPvkp (). GetTerritorialDepartment ())) {findParameters + = "and (Pvkp.guidTerritorialDepartment = '' + realTraffic.getPvkp (). GetTerritorialDepartment (). GetGuid () + '' or Pvkp.guidFtsDepartment = '' + realTraffic.getPvkp () getTerritorialDepartment () getGuid () + '') "..}}}I in this method The pass is a part of a huge set of complex checks. The question is how to deal with this kind of code - how many nested if there are checks and common approaches to making this code simpler and more elegant?
UPD: I understand that to avoid such code, while writing a new project, but with the existing legacy code There is a good guide to handling such things as "Chabil Code" from Uncle Bob in the book. In my case I want to say:
- Put string concatenations in a method ( And use
StringBuilder )
- Convert a
rest & amp; if for (condition)} for a
and if (condition)
consider adding companyType == CompanyBean.PP_TYPE;; RealTraffic.isSkipOther () In a different method, it is some kind of business logic, which Reader
Considers the reversal, then (realTraffic.getPvkp ()! =) For
if (realTraffic .getPvkp () == faucet) {return;}
to reduce block indentation.
- Convert a
No comments:
Post a Comment