שאלה על Design Pattern
אני רוצה המלצה לDP מסוים. לשם התחלה רק אציין שהקוד בג'אווה ואני משתמש בתפיסת Exception. הבעיה: יש לי שני COLLECTIONS שעל כל אחד מהם אני צריך לבצע בדיקות (שנתפסות בEXCEPTIONS). (יהיו לי יותר COLLECTIONS). הבדיקות הן מאוד דומות (עד ממש זהות). הנה הקוד של המתודה: הסיבה לשימוש בEXCEPTIONS היא מערכתית. מתודות הבדיקה זורקות את הEXCEPTIONS ואני פשוט צריך להתלבש עליהן. אין אפשרות לשנות את אותן מתודות ודרך העבודה שלהן. ברור לי שצריך DP. השאלה איזה? אשמח לכל דעה ועצה.
אני רוצה המלצה לDP מסוים. לשם התחלה רק אציין שהקוד בג'אווה ואני משתמש בתפיסת Exception. הבעיה: יש לי שני COLLECTIONS שעל כל אחד מהם אני צריך לבצע בדיקות (שנתפסות בEXCEPTIONS). (יהיו לי יותר COLLECTIONS). הבדיקות הן מאוד דומות (עד ממש זהות). הנה הקוד של המתודה: הסיבה לשימוש בEXCEPTIONS היא מערכתית. מתודות הבדיקה זורקות את הEXCEPTIONS ואני פשוט צריך להתלבש עליהן. אין אפשרות לשנות את אותן מתודות ודרך העבודה שלהן. ברור לי שצריך DP. השאלה איזה? אשמח לכל דעה ועצה.
public Collection<String> aaa(Collection<ServiceDTO> allServiceDtos) throws ServiceLocatorException, FinderException { final Collection<String> problemsColl = new ArrayList<String>(); final Collection<ServiceDTO> addDtosCollection = getAddDtos(allServiceDtos); final Collection<ServiceDTO> updateDtosCollection = getUpdateDtos(allServiceDtos); try { validateDtosCollection(addDtosCollection); } catch (CatalogException ce) { problemsColl.add(ce.getErrorDescription()); } try { checkInternalPortValidity(addDtosCollection); } catch (CatalogException ce) { problemsColl.add(ce.getErrorDescription()); } try { validatePortRange(addDtosCollection, false); } catch (CatalogException ce) { problemsColl.add(ce.getErrorDescription()); } for (ServiceDTO serviceToAdd : addDtosCollection) { try { checkServiceValidityForAdd(serviceToAdd); } catch (CatalogException ce) { problemsColl.add(ce.getErrorDescription()); } } try { checkInternalPortValidity(updateDtosCollection); } catch (CatalogException ce) { problemsColl.add(ce.getErrorDescription()); } try { validatePortRange(updateDtosCollection, true); } catch (CatalogException ce) { problemsColl.add(ce.getErrorDescription()); } for (ServiceDTO serviceToUpdate : updateDtosCollection) { try { checkServiceValidityForAdd(serviceToUpdate); } catch (CatalogException ce) { problemsColl.add(ce.getErrorDescription()); } } return problemsColl; }