<?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 Metehan Bolat on Medium]]></title>
        <description><![CDATA[Stories by Metehan Bolat on Medium]]></description>
        <link>https://medium.com/@metehan.bolat.ie?source=rss-5ad2679408e4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZKMJoCOT5PG6USGPPkcjJw.jpeg</url>
            <title>Stories by Metehan Bolat on Medium</title>
            <link>https://medium.com/@metehan.bolat.ie?source=rss-5ad2679408e4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 09:40:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@metehan.bolat.ie/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[Input Validation with View Extension| Android — Kotlin]]></title>
            <link>https://medium.com/@metehan.bolat.ie/input-validation-with-view-extension-android-kotlin-f81c6ea9d985?source=rss-5ad2679408e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f81c6ea9d985</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[extension]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Metehan Bolat]]></dc:creator>
            <pubDate>Fri, 09 Jun 2023 10:01:30 GMT</pubDate>
            <atom:updated>2023-06-20T22:09:46.258Z</atom:updated>
            <content:encoded><![CDATA[<h3>Input Validation with View Extension | Android — Kotlin</h3><p>Let’s talk about Input Validation. In mobile applications, we often need to interact with the user. Especially on screens that require registration, login, credit card information or personal information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/286/1*VnomJjc1NxsAyaAmV_MtSg.png" /><figcaption>Input Fields</figcaption></figure><p>There are several methods for validating the input fields we saw above. Each input field must contain a unique rule. For example, we should create a rule that understands whether the value entered for the email field conforms to the email standards. Apart from these unique rules, we may have some common rules for all input fields. For example, a common rule is required so that the field is not empty.</p><p>Instead of writing separate functions on the screen where each input field is located, we can start by writing an extension for the view we will use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rowhwbCjcVQ2A4-owMcYfQ.png" /><figcaption>View Extension</figcaption></figure><p>As you can see above, we are writing an extension to the view (TextInputEditText) with which we interact with the user.</p><h3>Validation Rule</h3><blockquote>Callback</blockquote><p>I want a rule list containing the validations I want to make in the input field, as a parameter to the extension I wrote. I can also create a <strong>callback</strong> that returns the values I want<strong> (TextInputEditTextUIModel) </strong>when the field used gives an error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5PRCn1ByHi3MiIz8fa_CVA.png" /><figcaption>TextInputEditTextUIModel</figcaption></figure><blockquote>Rules</blockquote><p>Let’s get to the rules. Let’s get to the rules. First, I need to create a class that all the rules I’m going to create can inherit. Within this class, we can keep constant values of other rule classes that will inherit this class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yBt6XhcopE80xyAFXapjow.png" /><figcaption>Validation Rule</figcaption></figure><p>You can see the class that rule classes will inherit from above. I think I don’t need to explain why it’s an open class :)</p><blockquote>Error Message</blockquote><p>I mentioned that we created this class to manage error messages according to certain rules. If the current rule doesn’t need to give an extra error message, it can use the default message in the class it inherits from. We write using <strong>open</strong> so that we can override this variable in the classes we inherit.</p><blockquote>Predicate</blockquote><p>Using Predicate, we will create our rules. We create these rules for the input fields that we interact with the user. For this reason, we can say that Predicate will receive a String value. If you are not familiar with using Predicate, you can <a href="https://developer.android.com/reference/androidx/core/util/Predicate">click here</a>. We will use the <strong>test </strong>method here. To put it briefly, the test method will check whether the rule we wrote under the predicate scope matches the string we have given.</p><blockquote>Companion Object</blockquote><p>As I mentioned earlier, we can create constant values of specific rule classes that will inherit this class here. For example <strong>PHONE_NUMBER_LENGTH</strong></p><h3>Specific Rule Classes</h3><blockquote>Empty Text Rule</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L_tVk_yToCnM9aJTzTa-bw.png" /><figcaption>EmptyTextRule</figcaption></figure><p>We start by inheriting the main rule class we created. Then we override the default message we give by default and give a different message for this specific rule class. This way, I don’t need to add it to the constructor of the class I inherit. And I tell Predicate under which condition this rule I created will work. As we can understand from the name of the rule here, we want the rule to work if the value entered by the user <strong>isNullOrEmpty</strong>.</p><p>Let’s create a slightly more complex rule. Let’s even do it using that Regex that everyone hates.</p><blockquote>Phone Number Rule</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2B0FHKGi9xhoq-dhXxJx8w.png" /><figcaption>PhoneNumberRule</figcaption></figure><p>Here we create a regex for the value entered by the user. As you can see it’s a simple regex. It just uses numbers. Our rule is created according to the value returned from the regex. Here we will check the phone number length and whether the first value entered by the user is 5. I mentioned PHONE_NUMBER_LENGTH before. You can see it by swiping up.</p><p>Now that we understand the parameters we want with our extension, let’s continue.</p><p>The view where we get data from the user is a <strong>TextInputEditText</strong>. And we use TextInputLayout as its parent. This will make it easier for us to show the error messages and set the error colors.</p><p>You can see a sample input field below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kgSjfcv8Izl7t2jwrzZjAg.png" /></figure><p>Now I need to reach TextInputLayout through this view extension I created.</p><p>As you can see from the XML code above, <strong>the parent</strong> of the view we wrote the extension is <strong>TextInputLayout</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*utu_BHFcU6VU3GTnT5GVKw.png" /><figcaption>Parent View</figcaption></figure><p>If you noticed, I used just one parent word. But in the code you see above, I had to use two parents to reach the TextInputLayout. The question we have to ask here is very simple :) <strong>Why?</strong></p><blockquote>To find the answer to this question, we need to dig deep into the TextInputLayout. But this article is not about that. If you haven’t found out despite your research, you can<strong> </strong><a href="https://linktr.ee/metehanbolat"><strong>contact me here</strong></a>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OKk0aPscCEw04jA9S8ipHg.png" /><figcaption>doAfterTextChanged</figcaption></figure><p>With the code you see above, we follow the user input and if there is a previous error in the input field, we ensure that the error messages disappear as soon as the user changes the value entered.</p><blockquote>Let’s come to where we do the important work.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hpkuWtZo4k_1SQQ9kcJV_w.png" /><figcaption>Rule Control</figcaption></figure><p>First, we get the text that the user enters. (validateText)</p><p>We got the rules in a list. Therefore, the first thing we need to do is create a loop for the rules. In this way, we will reach all the rules one by one. Using rules[i], we reach the rule that is in order in the list. This list includes the <strong>ValidationRule</strong> classes.</p><p>Let’s take the first rule, aka rules[1].</p><p>I said earlier that we will use Predicate’s test method. We check the condition we created in the rule with the text we received from the user. If this method returns true, it means that the rule we created did not match the value entered by the user. For this reason, we get the error message we created in the rule class and give it to the error function of the TextInputLayout. When we show an error message to the user, we can use the callback we created by invoking it. We also say that the extension should return false because the user got an error.</p><blockquote><strong>Let’s see how to use it now.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gkD_bNj7dmfccCPKAWoqQA.png" /></figure><p>As you can see above, we define the relevant rules for the input fields by creating a function.</p><blockquote><strong>A little note, the order of the rules you put in the list is important!!</strong></blockquote><p>For example, if we don’t give the rule that we checked empty at first, it probably won’t work at all.</p><p>That’s enough info :) Now let’s see how it looks in real life.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NjfVFPqafP_7em34tViWSA.gif" /></figure><p>That’s all I have to say.</p><p>I hope it was useful content. If you want to follow me here is the link.</p><p><a href="https://linktr.ee/metehanbolat">https://linktr.ee/metehanbolat</a></p><p>Take care and keep reading.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Sk0yd4CmZNMCaK4N" /><figcaption>Photo by <a href="https://unsplash.com/ja/@peet818?utm_source=medium&amp;utm_medium=referral">Pete Pedroza</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f81c6ea9d985" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ktor Client]]></title>
            <link>https://medium.com/@metehan.bolat.ie/ktor-client-9e357d310ffd?source=rss-5ad2679408e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e357d310ffd</guid>
            <category><![CDATA[ktor]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[clients]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[Metehan Bolat]]></dc:creator>
            <pubDate>Sun, 24 Jul 2022 01:15:34 GMT</pubDate>
            <atom:updated>2022-07-24T01:20:52.243Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v7CfhJbpRLMhZOw-c7eFfw.png" /></figure><h3>What is Ktor?</h3><p><a href="https://ktor.io/docs/welcome.html">Ktor is a framework to easily build connected applications — web applications, HTTP services, mobile and browser applications.</a> Actually it is not just a backend framework but also a <strong><em>client</em></strong> like OkHttp.</p><p>So we can use Ktor to send network request to API and get response. We can already do this very simply using OkHttp and Retrofit. So why Ktor?</p><p>Let’s say we are going to make an application using KMM. At some point we will need to establish common structures for IOS and Android platforms. OkHttp and Retrofit libraries we use are Java and Android libraries. So, we can’t use the layer we created using these technologies for IOS. We need to create a separate layer for iOS. We can use ktor, which is a network client for both ios and android, as a single layer, as it is written in pure kotlin.</p><p>Let’s start coding..</p><h3>Request - Response Model</h3><p>Let’s create our <strong><em>Request </em></strong>and <strong><em>Response </em></strong>models according to the service we will use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*bZJkE0DeNEo0M7L7NLW2-Q.png" /><figcaption>Request Model</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*fnnRBv4en2N_4HgYLVSSFQ.png" /><figcaption>Response Model</figcaption></figure><blockquote><strong><em>What is Serializable?</em></strong></blockquote><p><a href="https://kotlinlang.org/docs/serialization.html"><strong><em>Serialization </em></strong>is the process of converting data used by an application to a format that can be transferred over a network or stored in a database or a file.</a></p><h3>Service Interface</h3><p>Where we define functions for what we want to do in Service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AWTpkBLt2q2Z79kYv513BA.png" /><figcaption>Functions we use for Service</figcaption></figure><h3>Http Routes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*igf5WoJ3Kpzgd8s2Xm4RpQ.png" /><figcaption>Http Routes</figcaption></figure><h3>Service Interface Implementation</h3><p>In this section, we create the logic to send a request to the service by override the necessary functions we created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g3xjgOQL7ZknSiv5ZoK8eQ.png" /></figure><p>We can try to make a request to the service using the try-catch block and catch errors if we fail. However, we need to create an instance from Http Client so that we can send service requests. Let’s go back to our interface to create this.</p><h3>Create Http Client Instance</h3><p>Since we do not use dependency injection in this project, we must manually create an instance of the parameter we give as the constructor. We can do this in the interface as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WFMR9kXEP8roB-s4igH8fg.png" /><figcaption>Http Client Instance</figcaption></figure><h3>Using Service</h3><p>Now all you have to do is access the object we created above on the page where you will use the service and functions. That is all. All you have to do is a simple design and see the results. I leave a sample design below for you to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kQCk7On1kI-Rq12HIXbtCA.png" /><figcaption>Sample Design</figcaption></figure><blockquote><strong>I hope it was useful content. Take care and see you in the next content.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*lzqq_kCQFODdBnZF0xOi8w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L1qYPk7OYjZ4FHQR" /><figcaption>Photo by <a href="https://unsplash.com/@manucosen?utm_source=medium&amp;utm_medium=referral">Manuel Cosentino</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e357d310ffd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Layout Managers (Recycler View)]]></title>
            <link>https://medium.com/@metehan.bolat.ie/layout-managers-recycler-view-28d41ed89baa?source=rss-5ad2679408e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/28d41ed89baa</guid>
            <category><![CDATA[recyclerview]]></category>
            <category><![CDATA[layoutmanager]]></category>
            <category><![CDATA[smoothscroller]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Metehan Bolat]]></dc:creator>
            <pubDate>Thu, 16 Jun 2022 22:49:10 GMT</pubDate>
            <atom:updated>2022-06-17T07:55:51.024Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are working with lists, you have probably used adapters. On Android we mostly use <strong><em>RecyclerView</em></strong>. This story is not about <strong><em>RecyclerView</em></strong>. It is related to the <strong><em>Layout Manager</em></strong> we use in<strong><em> RecyclerView</em></strong>.</p><p>A <strong><em>LayoutManager</em></strong> is responsible for measuring and positioning item views within a RecyclerView as well as determining the policy for when to recycle item views that are no longer visible to the user. For more detailed information about Layout manager, you can <a href="https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager#:~:text=A%20LayoutManager%20is%20responsible%20for,longer%20visible%20to%20the%20user.">click here</a>.</p><p>There are 3 types of Layout Managers.</p><ul><li>LinearLayoutManager</li><li>GridLayoutManager</li><li>StaggeredGridLayoutManager</li></ul><h3>Linear Layout Manager</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gp6_Z3tHfJ2KH9pglv_36A.png" /><figcaption>Linear Layout Manager</figcaption></figure><h3>Grid Layout Manager</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aKNDxT_2gpemA_k8BSYJfg.png" /><figcaption>Grid Layout Manager</figcaption></figure><h3>Staggered Grid Layout Manager</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w-j3sfTlsxWJElG7cO_p7g.png" /><figcaption>Staggered Grid Layout Manager</figcaption></figure><p>I think it is more correct to express it with visuals in order to understand the Layout Managers. Layout Managers have many functions that we can change. In this story we will see the class <strong><em>LinearSmoothScroller</em></strong> using the <strong><em>smoothScroolToPosition</em></strong> function.</p><p>We create a class that inherits from the <strong><em>Linear Layout Manager</em></strong>. By overriding the <strong><em>smoothScroolToPosition</em></strong> function, we can show an animated transition to the index we want in the list. If we want, we can even adjust the animation speed by overriding the <strong><em>calculateSpeedPerPixel</em></strong> function within the <strong><em>LinearSmoothScroller</em></strong> structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4rXVHykEy8YB7-nZwxhKJg.png" /><figcaption>Required Codes</figcaption></figure><p>The rest is exactly as you know. Create a normal recycler view adapter. Set the layout manager of the recyclerview you created in your design as the layout manager you created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*moMNJ8oeyTqw3wfqqm64Ug.png" /><figcaption>an Example for Recycler View Layout Manager</figcaption></figure><p>If you want, <a href="https://github.com/metehanie/RecyclerViewAutomaticSwipe">you can find the source code of the sample project here.</a> If you want to learn how the sample project is coded, <a href="https://www.youtube.com/watch?v=b92U2Fga8nY">you can also watch this video.</a></p><p>Thanks for reading this story. I hope it was useful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Nb8O3VOOe-lo-TzZ" /><figcaption>Photo by <a href="https://unsplash.com/@peet818?utm_source=medium&amp;utm_medium=referral">Pete Pedroza</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28d41ed89baa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Biometric Authentication — Android]]></title>
            <link>https://medium.com/@metehan.bolat.ie/biometric-authentication-android-b128fa6f979c?source=rss-5ad2679408e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/b128fa6f979c</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[biometric-authentication]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Metehan Bolat]]></dc:creator>
            <pubDate>Tue, 07 Jun 2022 22:50:23 GMT</pubDate>
            <atom:updated>2022-06-07T22:50:23.728Z</atom:updated>
            <content:encoded><![CDATA[<h3>Biometric Authentication — Android</h3><p>In the old days, we had to enter information such as email, username and password to log in. Until we reach the technological level that can use our biometric data. Thanks to this technology, we can log in wherever we want using only our finger. In this article, I always say finger, but remember that the face and iris are used as biometric data.</p><p>In this article, I will show you how we can log in on android using our biometric data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*NaOJLmBBZeYbCfULvKd9pA.png" /></figure><blockquote><strong>1- Dependency</strong></blockquote><p>First of all, we have a dependency that we need to add to the module level gradle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o-q5AHtHsmBSILmMk-5ilA.png" /><figcaption>Required dependency to log in using biometric data</figcaption></figure><blockquote><strong>2- Biometric hardware information of the device</strong></blockquote><p>We’ve added our required dependency. Now we need to check the biometric hardware status of the device that we want to log in with biometric data. Depending on the biometric hardware status of the device, you can take the actions you want in this section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*59puVOrXeVbPmF1eAjS3MA.png" /><figcaption>Biometric Manager</figcaption></figure><p>For example, <strong>BIOMETRIC_ERROR_UNSUPPORTED</strong> works if the device has a biometric hardware but is not supported. Another example, if the device does not have biometric hardware, “BIOMETRIC_ERROR_NO_HARDWARE” works. You can find more details about this part <a href="https://developer.android.com/training/sign-in/biometric-auth#available">here</a>.</p><blockquote><strong>3- Lateinit variables</strong></blockquote><p>We have to make some definitions in order to follow the results of the action made using the system dialog and biometric data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Phg4WTFvqbnOqdI26koecQ.png" /><figcaption>Lateinit variables</figcaption></figure><p>We see that two variables are related to biometric data. So what is<strong> Executor</strong>?</p><p>Simply put, executor is an object that executes submitted Runnable tasks. If you are familiar with <strong>Threads</strong>, I can give the following example. Executor can be thought of as an object used instead of creating threads. For much more detailed and comprehensive information on this subject, <a href="https://developer.android.com/reference/kotlin/java/util/concurrent/Executor">click here</a>.</p><p>This is how we can create the executor:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*23sv190UGYh7HlNP90HtEQ.png" /><figcaption>Create the executor</figcaption></figure><blockquote><strong>4- Dialog</strong></blockquote><p>In this part, we can use the system dialog by making a few adjustments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pi02rFrBPy7i5QrgYlEerw.png" /><figcaption>Required codes for System Dialog</figcaption></figure><p>You can define, for example, a button to call the dialog. If you used a button, you should do the following when it is clicked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lCCuKVnipC_6JRA_tHrwUA.png" /><figcaption>Required code to open the dialog</figcaption></figure><p>After clicking the button with these code blocks, we will get an view like the one below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*tfxXMW_XjNKnM4DXb6fUCA.jpeg" /><figcaption>System Dialog View</figcaption></figure><blockquote><strong>5- After biometric data entry</strong></blockquote><p>This part is the code block where the results are obtained according to the control of our biometric data that we use after the dialog is opened.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ObFwSycnmfxYaXSX73Kiw.png" /><figcaption>Biometric Prompt Authentication Callback</figcaption></figure><ul><li><strong><em>onAuthenticationError =&gt; </em></strong>In this section, for example, we get the warning we will receive when we make too many wrong attempts.</li><li><strong><em>onAuthenticationSucceeded =&gt; </em></strong>This part works if the biometric data is received correctly and the match is successful.</li><li><strong><em>onAuthenticationFailed =&gt; </em></strong>This part works if the biometric data was received correctly but did not match the correct data. For example, if someone other than you tries to log in using their biometric data.</li></ul><p>Yes! That’s all. Thanks for reading, I hope it helps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*04wMSdHbbjTTjFdl" /><figcaption>Photo by <a href="https://unsplash.com/@peet818?utm_source=medium&amp;utm_medium=referral">Pete Pedroza</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b128fa6f979c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scope Functions | Kotlin]]></title>
            <link>https://blog.devgenius.io/scope-functions-kotlin-5131391ac48d?source=rss-5ad2679408e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5131391ac48d</guid>
            <category><![CDATA[software]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-scope-functions]]></category>
            <dc:creator><![CDATA[Metehan Bolat]]></dc:creator>
            <pubDate>Sun, 23 Jan 2022 22:53:45 GMT</pubDate>
            <atom:updated>2022-02-01T21:53:31.342Z</atom:updated>
            <content:encoded><![CDATA[<p>There are five different <strong>scope functions</strong> that we can use when we want to execute a code block for context of an object. This is a temporary scope. Within this scope, we can access the object without using its name.</p><p><a href="https://kotlinlang.org/docs/scope-functions.html">Basically, these functions do the same: execute a block of code on an object. What’s different is how this object becomes available inside the block and what is the result of the whole expression.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*Sn6Lt3dsNv_ura8MEESXkw.png" /><figcaption>Table of key differences</figcaption></figure><h3><strong>.let { it -&gt;</strong></h3><p>Let is usually used for null check.</p><p>Even if we check for null with <strong>“if”</strong>, a different thread may access the variable and cause the application to crash. Also, the variable is still a nullable type.</p><pre>if (number != null) {<br>    val number2 = <em>number</em> + 1 // Number variable throws an error.<br>}</pre><p>That’s why we have to use let. We can also declare the let block as a value. The last line of the let block will act as a return. Also, we can use <strong>elvis operator</strong> with the let block. If we use the elvis operator, our variable type will not be nullable.</p><pre>val x = number?.<em>let </em><strong>{<br>    </strong>val number2 = <strong>it </strong>+ 1<br>    number2<br><strong>} </strong>?: 3</pre><h3>}</h3><h3>.apply { this -&gt;</h3><p>If we use apply when we are going to use more than one property or one property of a class many times, we don’t need to use the object of the class each time.</p><pre>val intent = Intent().<em>apply </em><strong>{<br>    </strong>putExtra(&quot;&quot;, &quot;&quot;)<br>    putExtra(&quot;&quot;, 0)<br>    <em>action </em>= &quot;&quot;<br><strong>}</strong></pre><h3><strong>}</strong></h3><h3>.run { this -&gt;</h3><p>Run works like with. But when we use to run, if we want to assign a variable or value, we must return the type we want in the last line, otherwise, it will be a unit.</p><pre>val intent2 = Intent().<em>run </em><strong>{<br>    </strong>putExtra(&quot;&quot;, &quot;&quot;)<br>    putExtra(&quot;&quot;, 0)<br>    <em>action </em>= &quot;&quot;<br>    this<br><strong>}</strong></pre><h3>}</h3><h3>with() { this -&gt;</h3><p>A non-extension function: <strong>the context object</strong> is passed as an argument, but inside the lambda, it’s available as a receiver (this). <strong>The return value</strong> is the lambda result. In my opinion, with same as apply. I don’t know how they differ from each other.</p><pre>val intent3 = <em>with</em>(Intent()) <strong>{<br>    </strong>putExtra(&quot;&quot;,&quot;&quot;)<br><strong>}</strong></pre><h3>}</h3><h3>.also { it -&gt;</h3><p><strong>The context object</strong> is available as an argument (<strong><em>it</em></strong>). <strong>The return value</strong> is the object itself.</p><p><strong>Also </strong>is good for performing some actions that take the context object as an argument. Use <strong>also </strong>for actions that need a reference to the object rather than its properties and functions, or when you don&#39;t want to shadow <strong>this </strong>reference from an outer scope.</p><pre>fun getSquaredI() = (i * i).<em>also </em><strong>{<br>    </strong>i++<br><strong>}</strong></pre><h3>}</h3><p>What I have told is only a summary of the explanations. You can check the <a href="https://kotlinlang.org/docs/scope-functions.html#also"><strong><em>link</em></strong></a><strong><em> </em></strong>for more detailed information.</p><blockquote>Thanks for reading, I hope it was helpful.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LyC7wQiVsNNdVRWx" /><figcaption>Photo by <a href="https://unsplash.com/@astute?utm_source=medium&amp;utm_medium=referral">Rik van der Kroon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5131391ac48d" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/scope-functions-kotlin-5131391ac48d">Scope Functions | Kotlin</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[Dependency Injection with Hilt (Kotlin)]]></title>
            <link>https://blog.devgenius.io/dependency-injection-with-hilt-kotlin-562963c6c779?source=rss-5ad2679408e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/562963c6c779</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[dagger-hilt]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Metehan Bolat]]></dc:creator>
            <pubDate>Wed, 05 Jan 2022 21:40:47 GMT</pubDate>
            <atom:updated>2022-01-24T18:48:58.466Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/297/1*6tHWmspyG-13IWjPk6BbjA.png" /></figure><p>For a long time, <strong><em>Dagger </em></strong>was used to do <strong><em>Dependency Injection</em></strong> operations. However, <strong><em>Hilt</em></strong> has recently been included on of <strong><em>Dagger</em></strong> as a Jetpack Element. In this way, we had a much easier and much more efficient <strong>Dependency Injection</strong> framework that We can use on Android.</p><p>So, What is that <strong>Dependency Injection</strong>?</p><h3>Dependency Injection</h3><p>In its simplest form, we can think of it as a library that automates <strong><em>Instance </em></strong>creation. It may be easier to explain through examples. So, let’s create an Android App.</p><p>1- ) First, add the <strong><em>hilt-android-gradle</em></strong> plugin to your project’s root <strong><em>build.gradle</em></strong> file:</p><pre>buildscript {<br>    ...<br>    dependencies {<br>        ...<br>        classpath &#39;com.google.dagger:hilt-android-gradle-plugin:2.38.1&#39;<br>    }<br>}</pre><p>2- ) Then, apply the Gradle plugin and add these dependencies in your <strong><em>app/build.gradle</em></strong> file:</p><pre>...<br>plugins {<br>  id &#39;kotlin-kapt&#39;<br>  id &#39;dagger.hilt.android.plugin&#39;<br>}</pre><pre>android {<br>    ...<br>}</pre><pre>dependencies {<br>    implementation &quot;com.google.dagger:hilt-android:2.38.1&quot;<br>    kapt &quot;com.google.dagger:hilt-compiler:2.38.1&quot;<br>}</pre><p><strong>Note:</strong> Projects that use Hilt require Android Studio 4.0 or higher.</p><p>3- ) Hilt uses Java 8 features. To enable Java 8 in your project, add the following to the <strong><em>app/build.gradle </em></strong>file:</p><pre>android {<br>    ...<br>    compileOptions {<br>        sourceCompatibility JavaVersion.VERSION_1_8<br>        targetCompatibility JavaVersion.VERSION_1_8<br>    }<br>}</pre><p>Okay, we have prepared an Android Project that we can use Hilt. So, let’s start.</p><h3>Hilt Application Class</h3><p>First of all, the first thing we need to do is create a class. Then, inheriting this class from the Application class and we have to mark this class we created with <strong><em>a Annotation.</em></strong></p><pre>@HiltAndroidApp<br>class MyApplication : Application()</pre><p>We have to define the line below in the Manifest file.</p><pre>&lt;application<br>    android:name=&quot;.MyApplication&quot;<br>    ...</pre><p>This generated Hilt component is attached to the Application object’s lifecycle and provides dependencies to it. Additionally, it is the parent component of the app, which means that other components can access the dependencies that it provides.</p><h3>Inject Dependencies Into Android Classes</h3><p>Where Hilt will be used <em>-For example </em><strong><em>Activity</em></strong><em> or </em><strong><em>Fragment</em></strong><em>-</em> we have to open the relevant class and create an entry point as <strong><em>Annotation</em></strong>.</p><pre>@AndroidEntryPoint<br>class MainActivity : AppCompatActivity(){<br>      ...<br>}</pre><p>Hilt currently supports the following Android classes:</p><ul><li>Application (by using @HiltAndroidApp)</li><li>ViewModel (by using @HiltViewModel)</li><li>Activity</li><li>Fragment</li><li>View</li><li>Service</li><li>BroadcastReceiver</li></ul><p>If you annotate an Android class with @AndroidEntryPoint, then you also must annotate Android classes that depend on it. For example, if you annotate a fragment, then you must also annotate any activities where you use that fragment.</p><p>Let’s examine the <strong><em>Injection types</em></strong> on an example to make it more understandable.</p><pre>class Car(brand: Brand, engine: Engine) {</pre><pre>    fun information(){<br>        <em>println</em>(&quot;Car information...&quot;)<br>    }<br>}</pre><pre>class Engine {<br>    <br>}</pre><pre>class Brand {<br>    <br>}</pre><p>So, we have a class for cars and this class takes parameters from two other classes. While we need to create an object from a car class, we also need to create an object from the <strong><em>Brand</em></strong> and <strong><em>Engine</em></strong> classes.</p><p>In order for <strong><em>Instances</em></strong> to be created automatically, that is, to use <strong><em>Hilt</em></strong>, we must make our existing classes <strong><em>Injectable</em></strong>.</p><pre>class Car @Inject constructor(brand: Brand, engine: Engine) {</pre><pre>    fun information(){<br>        <em>println</em>(&quot;Car information...&quot;)<br>    }<br>    <br>}</pre><pre>class Engine @Inject constructor() {</pre><pre>}</pre><pre>class Brand @Inject constructor() {</pre><pre>}</pre><h3>Varieties of Injections</h3><blockquote><strong>Field Injection</strong></blockquote><pre>@AndroidEntryPoint<br>class MainActivity : AppCompatActivity() {<br>    // Field Injection<br>    @Inject<br>    lateinit var firstCar : Car</pre><pre>...<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_main</em>)</pre><pre>firstCar.information()</pre><pre>}</pre><blockquote><strong>Constructor Injection</strong></blockquote><pre>// Constructor Injection<br>class Brand @Inject constructor()</pre><h3>What is Scope?</h3><p><strong><em>Scope</em></strong> is not an <strong><em>Annotation</em></strong> that we have to use.</p><p>But if we are going to use it, we need to use it in accordance with the table below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VzxL_TiKu2K5lDQpeUHqTw.png" /></figure><p>We can create healthier projects if we specify in the Scope which class the Instances that Hilt will create will depend on.</p><p>Let’s specify a scope in our Car class that I showed above. First of all, look where we created an instance of the Car class.</p><p>The instance we created is in the MainActivity class. So this is an <strong>Activity Class. </strong>For this reason, we have 3 different scopes to choose from.</p><ul><li>@Singleton</li><li>@ActivityRetainedScoped</li><li>@ActivityScoped</li></ul><p>If we choose a scope below them, for example, @FragmentScoped, the application will throw an error. Because we used the class we created an instance in an activity, not in a fragment.</p><p>Well, then the following question should come to our mind, what would we do if we used the class that we will create instances both in the activity class and in the fragment?</p><p>The answer is very easy. Among the two scopes, whichever is higher in the table should be selected. For example, if we are creating an instance in both a view class and a fragment class, we should look at the table and select the FragmentScope.</p><h3>Interface Issues</h3><p>How we can work with <strong><em>Interface</em></strong> using <strong><em>Hilt</em></strong>?</p><p>Let’s first create an Interface and a class that implements it.</p><pre>interface MyInterface {</pre><pre>    fun myPrintFunction(): String</pre><pre>}</pre><pre>class MyInterfaceImplementor @Inject constructor() : MyInterface {</pre><pre>    override fun myPrintFunction(): String {<br>        return &quot;My Interface Implementor&quot;<br>    }</pre><pre>}</pre><p>Now let’s open another class and use this Interface that we created.</p><pre>class ClassExample @Inject constructor(<br>    private val myInterfaceImplementor: MyInterface<br>) {<br>    fun myFunction(): String {<br>        return &quot;Working:${myInterfaceImplementor.myPrintFunction()}&quot;<br>    }<br>}</pre><p>We cannot create an object from an Interface. For this reason, we need the InterfaceImplementor class that we created to use Interface. But we haven’t made such a definition in the above class yet.</p><p>So, If we try to run the below activity, we will get an error. Because we didn’t tell <strong><em>hilt</em></strong> how to <strong><em>initiliaze</em></strong> Interface.</p><pre>@AndroidEntryPoint<br>class MainActivity : AppCompatActivity() {</pre><pre>    @Inject<br>    lateinit var myClass : ClassExample</pre><pre>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_main</em>)</pre><pre><em>println</em>(myClass.myFunction())</pre><h3>Modules</h3><p>We need to use <strong>InstallIn Annotation</strong> when working with <strong>Modules</strong>. In InstallIn Annotation, we need to give a <strong>Component</strong> according to the table mentioned above.</p><blockquote><strong>@Binds</strong></blockquote><p>If we use this method, the class and function we will create must be <strong>abstract</strong>. According to the component given in InstallIn Annotation, we should give a Scope convenient for the function.</p><p>For example:</p><ul><li>@InstallIn(SingletonComponent::class) =&gt; @Singleton</li><li>@InstallIn(ActivityComponent::class) =&gt; @ActivityScoped</li><li>@InstallIn(FragmentComponent::class) =&gt; @FragmentScoped</li></ul><pre>@InstallIn(SingletonComponent::class)<br>@Module<br>abstract class MyModule {<br>    <br>    @Singleton<br>    @Binds<br>    abstract fun bindingFunction(myImplementor: MyInterfaceImplementor) : MyInterface</pre><pre>}</pre><blockquote><strong>@Provides</strong></blockquote><p>This is the method Android wants us to use also in my opinion it is easier than the previous method. All we have to do is tell the function that it will return an <strong><em>Interface</em></strong> and that interface will be the <strong><em>Implementor</em></strong> we created earlier.</p><pre>@InstallIn(ActivityComponent::class)<br>@Module<br>class MyModule {</pre><pre>    @ActivityScoped<br>    @Provides<br>    fun providerFunction() : MyInterface {<br>        return MyInterfaceImplementor()<br>    }<br>}</pre><p>This method is more comfortable to use with external libraries.</p><h3>Problem: Interface is bound multiple times!</h3><p>We only have one interface and only one class that implements it. Well, what if we had many implementor class that implement one interface?</p><p>We have to have used more explanatory annotations. For this reason, we must create our own annotations.</p><blockquote><em>In this case, we have one interface and two implementors as follows:</em></blockquote><pre>interface MyInterface {</pre><pre>    fun myPrintFunction(): String</pre><pre>}</pre><pre>class MyInterfaceImplementor @Inject constructor(): MyInterface {</pre><pre>    override fun myPrintFunction(): String {<br>        return &quot;My Interface Implementor&quot;<br>    }</pre><pre>}</pre><pre>class SecondInterfaceImplementor @Inject constructor() : MyInterface {</pre><pre>    override fun myPrintFunction(): String {<br>        return &quot;My Second Interface Implementor&quot;<br>    }</pre><pre>}</pre><p>Also, the class where we use these <strong>Interface </strong>and <strong>Implementors</strong> above should be as follows.</p><pre>class ClassExample @Inject constructor(<br>    private val myInterfaceImplementor: MyInterface,<br>    private val mySecondInterfaceImplementor: MyInterface<br>) {</pre><pre>    fun myFunction(): String {<br>        return &quot;Working: ${myInterfaceImplementor.myPrintFunction()}&quot;<br>    }</pre><pre>    fun secondFunction(): String {<br>        return &quot;Working: ${mySecondInterfaceImplementor.myPrintFunction()}&quot;<br>    }</pre><pre>}</pre><p>Finally, in our <strong><em>Module Class</em></strong>, we must define the second implementor class that we added.</p><pre>@InstallIn(SingletonComponent::class)<br>@Module<br>class MyModule {</pre><pre>    @Singleton<br>    @Provides<br>    fun providerFunction() : MyInterface {<br>        return MyInterfaceImplementor()<br>    }</pre><pre>    @Singleton<br>    @Provides<br>    fun secondProviderFunction() : MyInterface {<br>        return SecondInterfaceImplementor()<br>    }<br>}</pre><blockquote><em>We did everything. Well what’s the problem? Why is my app not working?</em></blockquote><p>Because we have connected two different implementors to an interface and we used two different functions from these implementors.</p><p>The functions we wrote in our <strong>Module Class</strong> return the MyInterface. But <strong><em>Hilt</em></strong> can’t find which <strong><em>Implementor</em></strong> to use from MyInterface. So we need to be more descriptive.</p><h3>Create Our Own Annotation</h3><p>We created two different annotations for two different implementors as follows.</p><pre>@Qualifier<br>@Retention(AnnotationRetention.<em>BINARY</em>)<br>annotation class FirstImplementor</pre><pre>@Qualifier<br>@Retention(AnnotationRetention.<em>BINARY</em>)<br>annotation class SecondImplementor</pre><p>Using these annotations, we can tell <strong><em>hilt</em></strong> which classes the implementors will use.</p><pre>@InstallIn(SingletonComponent::class)<br>@Module<br>class MyModule {</pre><pre>    @FirstImplementor<br>    @Singleton<br>    @Provides<br>    fun providerFunction() : MyInterface {<br>        return MyInterfaceImplementor()<br>    }</pre><pre>    @SecondImplementor<br>    @Singleton<br>    @Provides<br>    fun secondProviderFunction() : MyInterface {<br>        return SecondInterfaceImplementor()<br>    }<br>}</pre><p>Then, in the class where we use implementors, we need to tell the constructor these annotations we have created.</p><p>As follows:</p><pre>class ClassExample @Inject constructor(<br>    @FirstImplementor private val myInterfaceImplementor: MyInterface,<br>    @SecondImplementor private val mySecondInterfaceImplementor: MyInterface<br>) {}</pre><p>and that’s it for Dependency Injection with Hilt. Thank you for reading. I hope it was useful content for you.</p><p>I used <a href="https://developer.android.com/training/dependency-injection/hilt-android">Android Developers Docs</a> while creating this resource. If you want, you can view the source by clicking the link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NJ5MITp3uyNY6DRh" /><figcaption>Photo by <a href="https://unsplash.com/@redaquamedia?utm_source=medium&amp;utm_medium=referral">Denny Müller</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=562963c6c779" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/dependency-injection-with-hilt-kotlin-562963c6c779">Dependency Injection with Hilt (Kotlin)</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[Kotlin — Object Oriented Programming]]></title>
            <link>https://medium.com/@metehan.bolat.ie/kotlin-object-oriented-programming-594bd3bec85a?source=rss-5ad2679408e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/594bd3bec85a</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Metehan Bolat]]></dc:creator>
            <pubDate>Sun, 03 Oct 2021 12:52:12 GMT</pubDate>
            <atom:updated>2022-01-05T14:10:24.450Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kotlin — Object Oriented Programming</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WCg3_oZrcWZFYhVn" /><figcaption>Photo by <a href="https://unsplash.com/@mreichelt?utm_source=medium&amp;utm_medium=referral">Marc Reichelt</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Kotlin is an object oriented programming language. So what is this object oriented programming?</p><p><strong>Classes</strong></p><p>Objects are created from classes. A class is a blueprint for an object. Here is an example of an empty class.</p><pre>class Car {<br>    <br>}</pre><p><strong>Properties</strong></p><p>The data that classes have are called properties. For example, the car class has <strong><em>color</em></strong> and <strong><em>brand</em></strong><em> </em>features.</p><pre>class Car {<br><br>    var color : String? = null<br>    var brand : String? = null<br>}</pre><p><strong>Constructor</strong></p><p>It is used to create objects belonging to the class. One of the first functions called when an object is created from a class.</p><pre>constructor(colorInput : String, brandInput : String){<br>    this.color = colorInput<br>    this.brand = brandInput<br>}</pre><p><strong><em>Constructor</em></strong><em> </em>can be used like this. But in <strong><em>Kotlin</em></strong>, we can request more than one value directly in the parameter of the class. This type of writing is called a <strong><em>Primary Constructor</em></strong>.</p><pre>class Car(colorInput: String, brandInput: String) {<br><br>    var color : String? = colorInput<br>    var brand : String? = brandInput<br><br>}</pre><p>When we use primary constructor in Kotlin, we can use <strong><em>init</em></strong> function instead of constructor. The init function is also one of the first functions called when an object of the class is created.</p><pre>init {<br>    <em>println</em>(&quot;The first called function.&quot;)<br>}</pre><p><strong>Object Oriented Programming (OOP)</strong></p><p>As the title suggests, the foundation of OOP is objects. For a software, everything that contains functions that store data and perform operations with this data is an object. These objects have certain properties.</p><blockquote><em>* Encapsulation</em></blockquote><blockquote><em>* Inheritance</em></blockquote><blockquote><em>* Polymorphism</em></blockquote><p><strong>Encapsulation</strong></p><p>Controls whether the functions and capabilities of objects can be accessed by other objects.</p><blockquote><strong>Public </strong>=&gt; Every object can access.</blockquote><blockquote><strong>Protected</strong> =&gt; Subclasses inherited within the class can access it.</blockquote><blockquote><strong>Private</strong> =&gt; Accessible only from its own class.</blockquote><pre>public var color : String? = colorInput<br>protected var brand : String? = brandInput<br>private var year : Int? = yearInput</pre><p><strong>Inheritance</strong></p><p>Objects with the same function pass those functions to another class. In this way, by writing a single class, different objects can use their common properties by inheriting them.</p><pre>class Truck : Vehicle() {<br>    <br>}<br></pre><pre>class Car() : Vehicle() {<br><br>}</pre><p>Both a car and a truck are vehicles and can use vehicles features.</p><pre>open class Vehicle {<br><br>    var speed : Int? = null<br>    var color : String? = null<br>    var numberOfWheels : Int? = null<br>}</pre><p>The inherited class must be <strong><em>open</em></strong>.</p><p><strong>Polymorphisim</strong></p><p>When superclasses inherit from subclasses, they can show all the features of the subclass. But subclasses do not have to show all the properties that the superclass does.</p><p>Polymorphism can be applied in two different ways, statically and dynamically.</p><blockquote><strong>Static Polymorphism</strong></blockquote><p>It is called that the same functions used on the same class take different parameters.</p><pre>class Math {<br>    fun minus() : Int{<br>        return 0<br>    }<br>    fun minus(a : Int, b : Int) : Int{<br>        return a - b<br>    }<br>}</pre><p>The fact that an object created using this class can use the same function in two different ways is shown below.</p><pre>val math = Math()<br>math.minus() // return 0<br>math.minus(2,3)  // return -1</pre><blockquote><strong><em>Dynamic Polymorphism</em></strong></blockquote><p>Using an inherited class, we can access the functions and superclass of that class.</p><pre>open class Animal {<br>    open fun makeNoise(){<br>        <em>println</em>(&quot;Animal noise&quot;)<br>    }<br>}</pre><p>The Animal class is a superclass.</p><pre>class Cat : Animal() {<br>    fun animal(){<br>        super.makeNoise()<br>    }<br>    override fun makeNoise(){<br>        <em>println</em>(&quot;Meow&quot;)<br>    }<br>}</pre><p>The Cat class inherits from the animal class and can use animal functions.</p><pre>val animal = Animal()<br>animal.makeNoise() // return &quot;Animal noise&quot;<br><br>val midnight = Cat()<br>midnight.animal() // return &quot;Animal noise&quot;<br>midnight.makeNoise() // return &quot;Meow&quot;</pre><p>As seen above, an “animal” uses a function of its class. However, a ‘cat’ can use both ‘animal’ and ‘cat’ class functions. It can even overwrite the functions of the “animal” class and modify them accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZKKD9_iOpAo5b5tt" /><figcaption>Photo by <a href="https://unsplash.com/@peet818?utm_source=medium&amp;utm_medium=referral">Pete Pedroza</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=594bd3bec85a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>