<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anar Khalilov on Medium]]></title>
        <description><![CDATA[Stories by Anar Khalilov on Medium]]></description>
        <link>https://medium.com/@anarkhalilov?source=rss-52b787ffb5d5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sSjiBjE54IuTmUKiXjuiMw.jpeg</url>
            <title>Stories by Anar Khalilov on Medium</title>
            <link>https://medium.com/@anarkhalilov?source=rss-52b787ffb5d5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 15:24:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anarkhalilov/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Template Method Pattern]]></title>
            <link>https://blog.devgenius.io/template-method-pattern-dfb215411b10?source=rss-52b787ffb5d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/dfb215411b10</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[template-method-pattern]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <dc:creator><![CDATA[Anar Khalilov]]></dc:creator>
            <pubDate>Tue, 15 Jun 2021 08:26:59 GMT</pubDate>
            <atom:updated>2021-06-15T08:26:59.253Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aX8srEx2R9dvUKwvDCpI0g.jpeg" /><figcaption>By <a href="https://www.shutterstock.com/image-vector/japanese-konbini-shop-seller-give-products-1932080504">klyaksun</a></figcaption></figure><p>It is one of those scorching mid-summer days and you want nothing more than one huge ice cream. Coincidentally enough, you find yourself right in front of an ice cream booth (how convenient). You ask for a strawberry flavored ice cream while your friend wants a bottle of cold mineral water. There are two vendors, one serving you and the other serving your friend.</p><p>Each vendor takes the following actions in the orderly fashion:</p><ol><li>Says hello.</li><li>Prepares your order (depending on your need: ice cream, water, etc).</li><li>Hands you the product, takes the money and says “thank you”.</li></ol><p>This is a very simple 3 step algorithm a vendor is running for each and every order. While steps 1 and 3 in this procedure are standard for all customers, step 2 is customizable depending on the needs of the customer. So basically, a vendor has a standard procedure — a template — with empty holes that can be filled as needed.</p><p>This is the essence of the Template Method design pattern. A structure with holes in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*CQ1xvqDX0vbv8QUjiCSSFw.png" /><figcaption>Source: <a href="https://www.shutterstock.com/video/clip-12901958-malmo-sweden---circa-2015panning-put-your">shutterstock</a></figcaption></figure><p>Or to sound more technical, a base class method which has a pre-defined structure but at the same time some parts can be customized accordingly. This flexibility provides us with the best of both worlds.</p><p>From this base class, we can create an ice cream vendor, a mineral water vendor, a coffee vendor, etc.</p><p>Since all of these vendors will already have standard steps implemented in the base class, it will be sufficient to implement only the customizable step #2 like follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb38eb610232b6815ccdb61454521386/href">https://medium.com/media/bb38eb610232b6815ccdb61454521386/href</a></iframe><p>By applying this pattern, we:</p><ul><li>Avoid code duplication of standard steps.</li><li>Make the standard steps centralized so that the next time a change is needed, it will be sufficient to make changes only in one place.</li><li>Ensure the correct execution order of steps and make sure the skeleton is robust &amp; intact and unmodifiable from the outside.</li></ul><p>It is worth noting that in our example, the customizable <em>PrepareAndServeProduct</em> method is defined as abstract and therefore is mandatory to implement. We could have defined it as virtual to make the implementations optional, some or all.</p><p>Sometimes we develop techniques in an instinctive and natural way without knowing its conceptualized existence in the literature and it’s highly likely that you have already used this design pattern in your projects, knowingly or not. Now we know that this technique is called the “Template Method Pattern”.</p><p>As usual, you can find the source codes <a href="https://github.com/anar-khalilov/template-method-pattern">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dfb215411b10" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/template-method-pattern-dfb215411b10">Template Method Pattern</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On the Importance of UI Messages]]></title>
            <link>https://blog.devgenius.io/on-the-importance-of-ui-messages-baeb42503a97?source=rss-52b787ffb5d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/baeb42503a97</guid>
            <category><![CDATA[ui-design]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[ux-design]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Anar Khalilov]]></dc:creator>
            <pubDate>Wed, 24 Mar 2021 17:46:26 GMT</pubDate>
            <atom:updated>2021-06-12T09:46:57.706Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zkVu7Ob_7wbdHO9eK65Q3w.png" /><figcaption>By <a href="https://dribbble.com/marina_verdu">Marina Verdú</a></figcaption></figure><p>One day my company received complaints from one of our biggest customers and decided to send me and a co-worker to fix the issue on-site. Our application was supposed to read data from a text file and insert records into a database. However, when the button was pressed, nothing was happening.</p><p>After analyzing the source code, we noticed that the application was looking for a file at a specific folder with a specific name. When not found, it was doing nothing (empty <em>catch</em> block).</p><p>It took us literally 5 minutes to change the code to output a feedback message like the following: “<em>C:\XYZ\ABC.csv file was not found.</em>”</p><p>Only 5 minutes but it has cost our company:</p><ol><li>Three 40 km (25 mi) taxi rides to our customer’s office (one for me, one for the co-worker and one for returning back to the office).</li><li>Our half-day salaries as we spent our precious time on the road.</li></ol><p>Not to mention that it was an urgent matter and was unplanned for, it also compromised the projects we were currently working on and risked the release dates of these projects. A simple feedback message could have prevented all this mess — dissatisfaction on the customer’s side and unnecessary costs &amp; risks on the company’s side. The solution is really simple, but is almost always overlooked.</p><p>Fast forward a couple of days and I am short on time as the deadline of another project is right around the corner. I couldn’t make the application work as required since I was receiving an error message like “<em>an item was not found in cache</em>”. I spent nearly one day trying to figure out the problem and guess what? It was not directly related to the cache mechanism. The error was caused because there was a missing whitelist definition for the cache to work correctly. Now go figure that from the error message :). Another pitfall that could have been easily avoided.</p><p>It is impossible to overstate the importance of high-quality feedback messages. Ironically, they are often understated. And definitely underrated.</p><p>For instance, everyone is familiar with the following message:</p><blockquote>An error has been encountered, please try again later.</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FRqJVa0fl01w%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DRqJVa0fl01w&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FRqJVa0fl01w%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e992afe624ddd62cab75112470409480/href">https://medium.com/media/e992afe624ddd62cab75112470409480/href</a></iframe><p>We see these kind of messages everywhere: on the Internet, in a mobile app, during an ATM transaction, while watching our smart TVs, etc. The problem with these kind of messages is that they aren’t particularly helpful — they just state a fact. No tangible alternatives, no details and no directions on what the next step is.</p><p>On the other hand, it is impossible for the developer to predict all possible problems an application may face during its lifetime. Consequently, it becomes infeasible to plan a solution for each disaster beforehand.</p><p>It seems like fighting a losing battle.</p><p>We cannot prevent errors from occuring and they will be happen no matter how prepared you are. Life happens. But what we can do is, avoid generic messages whenever possible and focus on producing a meaningful feedback that have the following characteristics:</p><ol><li><strong>Concise</strong>: it must give a lot of information clearly and in a few words. Being just comprehensive is not good enough, it must also be brief.</li></ol><blockquote>You encountered this error because you didn’t fill in the textbox labelled “Name”. It is compulsory to enter a name.</blockquote><blockquote>INSTEAD: Please enter your name.</blockquote><p><strong>2. Specific</strong>: instead of presenting a general information to the user, a valuable feedback message must include specific details.</p><blockquote>You cannot use this discount coupon.</blockquote><blockquote>INSTEAD: You cannot use this discount coupon. This coupon is only for the “Books” category.</blockquote><p><strong>3. User-friendly</strong>: Displaying an “Object reference not set…” error to the user will only make them feel uncomfortable. Instead, spend a bit more effort by adding a null check and displaying a much more meaningful message.</p><p>(When the check-out button is pressed with an empty basket)</p><blockquote>Object reference not set to an instance of an object.</blockquote><blockquote>INSTEAD: You cannot check-out an empty basket.</blockquote><p><strong>4. Guiding</strong>: Just telling someone it is raining outside is not very helpful; you should offer him/her an umbrella . The end user shouldn’t feel the need to call customer service about what to do next. We need to predict what the user is trying to accomplish and provide solutions accordingly.</p><blockquote>Cannot complete your order because you don’t have any defined addresses.</blockquote><blockquote>INSTEAD: Cannot complete your order because you don’t have any defined addresses. Please go to “My Account” -&gt; Addresses and create a new delivery address.</blockquote><p>Feedback messages having these characteristics will most likely make the user feel relaxed. It will be as if the user is having a conversation with your application. It will not only make your users happier, but also save your time and effort in the long run.</p><p>Never ever underestimate the power of high-quality feedback messages.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=baeb42503a97" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/on-the-importance-of-ui-messages-baeb42503a97">On the Importance of UI Messages</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Build!]]></title>
            <link>https://blog.devgenius.io/builder-pattern-fd0fed6002ff?source=rss-52b787ffb5d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd0fed6002ff</guid>
            <category><![CDATA[builder-pattern]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Anar Khalilov]]></dc:creator>
            <pubDate>Fri, 22 Jan 2021 19:29:27 GMT</pubDate>
            <atom:updated>2021-01-25T12:07:20.882Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wxlg9_ZX_JX4OlnZ84fU6w.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@danist07?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">贝莉儿 DANIST</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Consider you own a website where people can buy/sell cars. Needless to say, you must have a search page where users can specify numerous search criteria. Similar to the page below from <a href="https://www.cars.com/for-sale/advanced-search/">cars.com</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*YW2bijWHL7pPkf9ltS8MaA.png" /></figure><p>How do you model this requirement?</p><p>Well, the first idea that comes to mind is to create and fill a search criteria instance and pass it to a method that will return results according to this criteria. Something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a01bd516eb6001dd5c8f83444423dac7/href">https://medium.com/media/a01bd516eb6001dd5c8f83444423dac7/href</a></iframe><p>Some issues with this approach:</p><ol><li>The most obvious issue here is the number of arguments. According to the research made by <a href="https://twitter.com/thebrainlady">Susan Weinschenk PhD</a>, limiting the information you give to people to four items is nearly optimal. Anything more than that and we, as humans, tend to forget or at least get stressed/feel uncomfortable about it. This and more in her brilliant book <a href="https://www.amazon.com/Things-Designer-People-Voices-Matter/dp/0321767535">100 Things Every Designer Needs to Know About People</a> which I highly recommend to everyone who develops software. After all, we — software developers are designers.</li><li>Another issue with methods that have a long list of arguments, is that you may easily lose track of which value is what. In the example above, by the time you come to the 8th parameter and see zero there, you may easily get confused as to what this value is. Is that a minimum mileage, a minimum price or even a binary value specifying whether the car has a sunroof or not. <strong>If you as a developer look at the code and get confused, it means that it was not designed properly</strong>. A well designed product is nonambiguous in the sense that it is self-explanatory or intuitive, leaves a pleasing experience and is simply beautiful.</li><li>What if a user specifies only body style and wants to list all cars with Sedan body style. What to we do? We just fill the first parameter and set everything to its default value like below:</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f9ab3687cfa5e044fc738e861b7c61a/href">https://medium.com/media/7f9ab3687cfa5e044fc738e861b7c61a/href</a></iframe><p>I am sure most of you will agree that it is quite ugly. A bunch of code with no added value and with a lot of question marks. <strong>A code with no added value is not only useless, but also harmful; it needs to perish</strong>.</p><p>I am not going to explain why we shouldn’t create and then call a new constructor for this case; I think it is quite obvious why it is not such a brilliant idea.</p><p>4. And last, but not least, I will leave you with the famous quote from <a href="https://twitter.com/unclebobmartin">Robert C. Martin</a>’s must read book <a href="https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882">Clean Code</a>:</p><ul><li><em>The ideal number of arguments for a function is zero (niladic).</em></li><li><em>Next comes one (monadic) followed closely by two (dyadic).</em></li><li><em>Three arguments (triadic) should be avoided where possible.</em></li><li><em>More than three (polyadic) requires very special justification — and then shouldn’t be used anyway.</em></li></ul><p>Even though at first he seems to emphasize the number of parameters, maybe the more important issue here is about software testing. If you have written any unit tests in your life or have a slight idea about it, you must be knowing that each new introduced parameter of a method requires you to create more and more test cases as the total number of parameters increase. The more variables a method has, the more complex its business logic is inclined to be.</p><p>So, how do we solve all these issues while at the same time keeping everything clean and simple? Well, as with every decision there are trade-offs. Changing the code will take our valuable time and energy but in the long run it will be well worth it. Both in terms of the product you are developing and your personal career/improvement.</p><p>Now compare these:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d429dc0eba5ef1f11fbd64c2ac539447/href">https://medium.com/media/d429dc0eba5ef1f11fbd64c2ac539447/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/412267a00d79bd1d50a7a13ffbbc3127/href">https://medium.com/media/412267a00d79bd1d50a7a13ffbbc3127/href</a></iframe><p>The latter looks like it was written by someone <a href="https://www.goodreads.com/quotes/7630389-clean-code-always-looks-like-it-was-written-by-someone">who cared</a>. Cared about the product (s)he was developing. Cared about the company (s)he was working for. Cared about teammates. Cared about her/his own reputation. And finally cared about the people whom (s)he will never know — fellow programmers that will work on the code long after (s)he is gone.</p><p>Notice that we chain methods one after another in a fluent manner (you can Google “method chaining”, “fluent interface”, “fluent API” if you are curious). I am sure you already know this technique as <a href="https://www.geeksforgeeks.org/linq-method-syntax/">method syntax in LINQ</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a08b31954b5226a722279245394a2d7f/href">https://medium.com/media/a08b31954b5226a722279245394a2d7f/href</a></iframe><p>I can hear my lazy inner voice complaining: why bother with all extra code when we can simply set only the needed properties?</p><p>Well, fair enough. :) I recommend you not to ignore your lazy inner voice simply because you may miss out on some <a href="https://www.goodreads.com/quotes/568877-i-choose-a-lazy-person-to-do-a-hard-job">shortcuts</a> and it may even <a href="https://www.telegraph.co.uk/money/consumer-affairs/lazy-procrastinating-could-make-wildly-successful/">make you successful</a>. Sometimes the best solution is the most straightforward one.</p><p>I am afraid to tell you however, this time it isn’t. Proposed lazy solution brings issues like:</p><ul><li>We need to avoid exposing all fields as public settable properties whenever possible and prefer constructors with read-only properties.</li><li><a href="https://www.codemag.com/Article/0705061/All-Input-Data-is-Evil-So-Make-Sure-You-Handle-It-Correctly-and-with-Due-Care">All input data is evil</a> and needs to be validated. If we don’t have any restriction/validation, the object may transform to an invalid state. To give an example, assume there are two properties, namely MinYear and MaxYear. When we set MinYear to 2019 and MaxYear to 2018, the object switches to an invalid state and it becomes pointless to search with this search criteria instance. Of course you could add some validations in the method that actually makes the search, but I firmly believe the object shouldn’t be in the wrong state in the first place.</li></ul><p>As you may have noticed from the Builder pattern code sample, there is a Build() method at the end. This method is the final link in the chain of methods and is a perfect place to add some rules like:</p><ul><li>MinYear cannot be greater than MaxYear.</li><li>A coupê must always have exactly two doors.</li><li>The number of cylinders a car may have must be between 1 and 12 .</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/985d2296952c90e6a9156ace0ca6d7fe/href">https://medium.com/media/985d2296952c90e6a9156ace0ca6d7fe/href</a></iframe><p>I don’t want to choke you with very long code blocks so I will leave a link where you can download all source code <a href="https://github.com/anar-khalilov/builder-pattern"><strong>here</strong></a>.</p><p>To sum things up, we use the Builder pattern when we need to create highly configurable objects in a simple, clean and sustainable way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd0fed6002ff" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/builder-pattern-fd0fed6002ff">Let’s Build!</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>