ত যাই হউক আমার এটা লেখার উদেশ্য হল আমার কিছু লারনিং সবার সাথে শেয়ার করা আর শেয়ার করব নিজের মাতৃ ভাষায় ...
সাধারন্ত ডেভলোপাররা কোড করার সময় ভাবে কিভাবে ফাংশনটা বানাবে. কিন্তু আদর্শ চর্চা হল আগে ভাবে কি ভাবে লজিক ফ্লো হবে .. একটা উদাহরন দেই :
someMethod(...) {
// start try block
// look up cache object instance in IoC container.
// retrieve the cache from cache manager.
// if DBSearchREsult found in cache
// create a new ResultPage object and set in page context
// return to a successful page
// otherwise create an empty ResultPage and set in page context
// log the warning
// return to a successful page
// catch exception and set exceptio in page context
// return to a failure page
}
একটা মেখড লেখার আগে সুডো কোডটা লেখা তার পর স্টেপ বাই স্টেপ কোড লিখলে বার বার চেষ্টা এবং ভুল হবার সম্ববনা খুবই কম ...
উদাহরন :
// start try block
try {
ArticleSearchForm articleSearchForm = (ArticleSearchForm) pActionForm;
// look up cache object instance in IoC container.
Cache cache = cacheFromGlobalBus();
// retrieve the cache from cache manager.
Object searchResultCacheObject = cache.getObject(
articleSearchForm.cacheKey());
// if DBSearchREsult found in cache
if (searchResultCacheObject != null) {
// create a new ResultPage object and set in page context
ResultPage resultPage = ....;
// return to a successful page
return pActionMapping.findForward(FORWARD_SUCCESS_PAGE);
} else {
// otherwise create an empty ResultPage and set in page context
ResultPage resultPage = ....;
// log the warning
LOG.warn("No result found, setting an empty result page");
// return to a successful page
return pActionMapping.findForward(FORWARD_SUCCESS_PAGE);
}
} catch (Exception e) {
// catch exception and set exception in page context
pRequest.setAttribute(
ArticleSearchAction.class.getName() + SUFFIX_ERROR, e);
// log the error message
LOG.warn("Search navigation action failed", e);
// return to a failure page
return pActionMapping.findForward(FORWARD_FAILURE_PAGE);
}
লারনিং নোট:
--------------
"কোড করার সময় না ভেবে কোড করার পূর্বে ভাবুন "
effective java বই টা পড়তে পারেন
সর্বশেষ এডিট : ৩১ শে ডিসেম্বর, ১৯৬৯ সন্ধ্যা ৭:০০