{"id":2613,"date":"2024-10-08T21:53:22","date_gmt":"2024-10-08T21:53:22","guid":{"rendered":"https:\/\/sgrsoftwaresolution.com\/us\/?p=2613"},"modified":"2024-10-08T21:53:24","modified_gmt":"2024-10-08T21:53:24","slug":"replace-conditional-statements-if-else-or-switch-with-factory","status":"publish","type":"post","link":"https:\/\/www.sgrsoftwaresolution.com\/us\/replace-conditional-statements-if-else-or-switch-with-factory\/","title":{"rendered":"Replace Conditional Statements (IF\/ELSE Or SWITCH) With Factory"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Tools Used for development<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Visual Studio 2019<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Long condition statement<\/h3>\n\n\n\n<p>In the below code snippet we can see a skill set which is suitable for a job opening in our company with a long condition statement, (i.e, switch statement we have used). Currently we have only two requirements. If we need to add more skills to switch statement then the conditions will keep on increasing.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.sgrsoftwaresolution.com\/images\/blog\/image13.png\" alt=\"\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Replacing condition statement with polymorphism<\/h3>\n\n\n\n<p>We will create a Simple Factory design pattern, with class name as SimpleFactory. We will create a skill Dictionary and in constructor add all the skill sets and return the value, as shown in below code snippet,<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.sgrsoftwaresolution.com\/images\/blog\/image14.png\" alt=\"\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Implementing lazy loading<\/h3>\n\n\n\n<p>In the above code, we have seen how we replace condition statement with Dictionary. Now we will see how we implement lazy loading.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.sgrsoftwaresolution.com\/images\/blog\/image15.png\" alt=\"\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Implementing lazy loading using Lazy class<\/h3>\n\n\n\n<p>In the above code, we have seen how we used lazy loading. Now we will see how we implement lazy loading using Lazy class from .Net framework.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.sgrsoftwaresolution.com\/images\/blog\/image16.png\" alt=\"\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Tools Used for development Long condition statement In the below code snippet we can see a skill set which is suitable for a job opening in our company with a long condition statement, (i.e, switch statement we have used). Currently we have only two requirements. If we need to add more skills to switch statement [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2614,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[33],"tags":[34],"class_list":["post-2613","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","tag-technology"],"_links":{"self":[{"href":"https:\/\/www.sgrsoftwaresolution.com\/us\/wp-json\/wp\/v2\/posts\/2613"}],"collection":[{"href":"https:\/\/www.sgrsoftwaresolution.com\/us\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sgrsoftwaresolution.com\/us\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sgrsoftwaresolution.com\/us\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sgrsoftwaresolution.com\/us\/wp-json\/wp\/v2\/comments?post=2613"}],"version-history":[{"count":1,"href":"https:\/\/www.sgrsoftwaresolution.com\/us\/wp-json\/wp\/v2\/posts\/2613\/revisions"}],"predecessor-version":[{"id":2615,"href":"https:\/\/www.sgrsoftwaresolution.com\/us\/wp-json\/wp\/v2\/posts\/2613\/revisions\/2615"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sgrsoftwaresolution.com\/us\/wp-json\/wp\/v2\/media\/2614"}],"wp:attachment":[{"href":"https:\/\/www.sgrsoftwaresolution.com\/us\/wp-json\/wp\/v2\/media?parent=2613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sgrsoftwaresolution.com\/us\/wp-json\/wp\/v2\/categories?post=2613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sgrsoftwaresolution.com\/us\/wp-json\/wp\/v2\/tags?post=2613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}