<?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 serhat şamioğlu on Medium]]></title>
        <description><![CDATA[Stories by serhat şamioğlu on Medium]]></description>
        <link>https://medium.com/@serhatsamioglu35?source=rss-a853e5e4a463------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*aHPzxjmUZ1Nf7T6Lr6EC0g.jpeg</url>
            <title>Stories by serhat şamioğlu on Medium</title>
            <link>https://medium.com/@serhatsamioglu35?source=rss-a853e5e4a463------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 15:01:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@serhatsamioglu35/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[12- AI Code Review in QNB Android Mobile]]></title>
            <link>https://medium.com/ibtech/13-ai-code-review-in-qnb-android-mobile-076165bff93c?source=rss-a853e5e4a463------2</link>
            <guid isPermaLink="false">https://medium.com/p/076165bff93c</guid>
            <dc:creator><![CDATA[serhat şamioğlu]]></dc:creator>
            <pubDate>Thu, 05 Dec 2024 13:23:29 GMT</pubDate>
            <atom:updated>2024-12-05T13:33:00.266Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9AxcFm8U8uppi0axbLzmlQ.jpeg" /></figure><p>Herkese selam, ben Serhat 👋</p><p>Yazılım geliştirme dünyası hızla değişiyor ve yeni teknolojiler, yazılım mühendislerinin <strong>daha verimli ve kaliteli kod</strong> yazmalarına olanak tanıyor. Bizde <strong>QNBAndroidMobile</strong> olarak bu yenilikleri takip ediyoruz. Son yıllarda yapay zeka (AI) tabanlı araçlar yazılım geliştirme sürecine entegre edilmeye başlandı ve bu teknolojilerden biri de &quot;<strong>AI Code Review</strong>&quot; sistemleridir. AI code review, yazılım mühendislerinin kodlarını <strong>gözden geçirme ve hata ayıklama</strong> süreçlerini hızlandırırken, aynı zamanda kaliteyi artırmak amacıyla kullanılan güçlü bir araçtır. Bu yazıda, AI code review <strong>nedir, nasıl çalışır ve yazılım geliştirme süreçlerine nasıl katkı sağlar</strong> gibi soruları ele alacağız. Ardından OpenAI Code Review Extension nedir ve entegrasyonu nasıl yapılır derinlemesine inceleyeceğiz.</p><h3>QnbAndroidMobile Code Review süreci 👀</h3><p>AI code review’a geçmeden önce bizim code review akışımız nasıl işliyor kısaca ondan bahsedeyim. PR açıldıktan sonra ilgili geliştirme <strong>Azure DevOps </strong>üzerinden yürüttüğümüz CI aşamasında build ediliyor.<strong>CI Build</strong> aşamasında <strong>unit testler</strong> çalışıyor ve <strong>Detekt</strong> ile <strong>static kod analizi </strong>yapılıyor. Detekt ile ilgili daha detaylı bilgi edinmek isterseniz <a href="https://medium.com/ibtech/1-static-code-analysis-detekt-in-qnb-android-mobile-5acd056b3206">buradan</a> makalemize ulaşabilirsiniz. CI aşamasından başarılı sonuç gelince review başlıyor. İlk olarak hangi modülde kod yazdıysak ilgili <strong>modül sahibi</strong> bir arkadaştan da onay almamız gerekiyor. Ardından senior veya üzeri bir arkadaşın <strong>teknik review</strong> yapması gerekiyor. Ek olarak <strong>configürasyonel(proguard, gradle ve dependencies) </strong>dosyalarında değişiklik yaptıysak takım liderimizden onay almamız gerekiyor.</p><p>Bu aşamalarda bir düzeltme ihtiyacı olduğu taktirde, geliştirmeyi yapan kişi kodu düzenleyip tekrardan bu aşamalardan geçiyor. Code Review sürecimizi daha detaylı incelemek isterseniz <a href="https://medium.com/ibtech/code-review-flows-in-qnbandroidmobile-4581ef6c64f4">buradan</a> makalemize ulaşabilirsiniz. Süreç böyle olduğundan dolayı review yapan kişiler <strong>birden fazla kez</strong> aynı geliştirmeyi review etmek zorunda kalıyor. Bu da <strong>zaman ve maliyet</strong> kaybına yol açıyor.</p><p>Bunun önüne geçmek için CI build aşamasında <strong>AI code review pipeline çalıştırıp</strong> AI’ın yakaladığı hataları önden düzeltip review yapan arkadaşların önüne <strong>standartlara uygun</strong> bir kod sunmayı hedefliyoruz.</p><h3>🤖 AI Code Review Nedir?</h3><p>AI code review, yazılım geliştirme sürecinde yazılan kodun otomatik olarak analiz edilmesi ve <strong>potansiyel hataların</strong>, <strong>güvenlik açıklarının, performans sorunlarının veya yazılım standartlarından sapmaların</strong> belirlenmesidir. Yapay zeka tabanlı sistemler, bu code review’i insan müdahalesine gerek kalmadan yaparak yazılımcılara önerilerde bulunur.</p><p>AI code review araçları, genellikle aşağıdaki alanlarda faydalı olabilir:</p><ul><li>🚫 <strong>Hata Tespiti:</strong> Yapay zeka, yazılımcıların gözden kaçırabileceği hataları ve potansiyel sorunları tespit eder.</li><li>💯 <strong>Kod Kalitesi:</strong> Kodun okunabilirliğini, tutarlılığını ve bakımı kolaylığını değerlendirir.</li><li>📈 <strong>Performans İyileştirmeleri:</strong> Performans sorunları veya verimsiz kod yapıları hakkında geri bildirim sağlar.</li><li>🔒 <strong>Güvenlik:</strong> Kodun güvenlik açıklarını veya potansiyel zayıf noktalarını belirler.</li><li>✔️ <strong>Kod Standartlarına Uygunluk:</strong> Yazılım standartları ve kodlama kurallarına uygunluk kontrolü yapar.</li></ul><h3>AI Code Review Nasıl Çalışır?</h3><p>AI code review araçları, genellikle şu adımları takip eder:</p><ol><li>📊 <strong>Kodun Analizi:</strong> Yapay zeka, yazılımcıların yazdığı kodu analiz eder. Bu analiz, statik analiz yöntemleri ile yapılır, yani kodun çalıştırılmadan doğrudan review edilmesidir.</li><li>🔎 <strong>Hata ve Sorun Tespiti:</strong> AI, yazılan kodda potansiyel hataları, performans hatalarını, güvenlik açıklarını veya kodlama standartlarından sapmaları tespit eder.</li><li>🤖 <strong>Öneriler ve Düzeltmeler:</strong> Yapay zeka, bulduğu sorunları yazılımcıya bildirir ve bu hataların nasıl düzeltileceğine dair önerilerde bulunur. Bu öneriler, belirli bir kod satırında yapılması gereken düzeltmeler veya kodun yeniden yapılandırılması şeklinde olabilir.</li></ol><h3>AI Code Review Avantajları</h3><ul><li>⏳ <strong>Zaman Tasarrufu:</strong> İnsanlı code review zaman alıcı olabilir. AI tabanlı araçlar, büyük kod tabanlarını hızlı bir şekilde analiz ederek yazılımcıların zamanını önemli ölçüde azaltabilir.</li><li>⛔ <strong>Hata Oranının Azaltılması:</strong> AI araçları, gözden kaçabilecek hataları ve sorunları tespit etme konusunda çok başarılıdır. Bu, yazılımcının hatalarını erken bir aşamada fark etmesine yardımcı olur ve üretim ortamına hatalı kodun gitmesini engeller.</li><li>📈 <strong>Kod Kalitesinin Artırılması:</strong> AI, sadece hataları bulmakla kalmaz, aynı zamanda kodun okunabilirliğini ve tutarlılığını artırmaya yönelik önerilerde de bulunur. Bu, kodun bakımını kolaylaştırır ve ekipler arasında daha iyi bir işbirliği sağlar.</li><li>🔒 <strong>Daha Yüksek Güvenlik:</strong> Yapay zeka, güvenlik açıklarını tespit etmede özellikle etkili olabilir. AI code review araçları, yaygın güvenlik zafiyetlerine karşı kodu tarar ve güvenlik açıklarının önceden belirlenmesine yardımcı olur.</li><li>🚀 <strong>Ekip Performansını Artırma:</strong> AI tabanlı araçlar, code review’lerdeki yükü azaltarak yazılımcıların daha verimli çalışmasına olanak tanır. Bu, ekiplerin daha hızlı ve yüksek kaliteli yazılımlar geliştirmelerine yardımcı olur.</li></ul><h3>֎ OpenAI Code Review Extension Nedir?</h3><p><strong>OpenAI Code Review Extension</strong>, OpenAI’nin GPT tabanlı yapay zeka modellerini kullanarak, yazılımcıların yazdığı kodu otomatik olarak gözden geçiren ve geri bildirim sağlayan bir araçtır. Bu uzantı <strong>kod depolama platformları</strong> ile entegre olabilir ve yazılımcılara yazdıkları kodla ilgili önerilerde bulunur. Ayrıca, hataları, güvenlik açıklarını, kodlama standartlarına uyumsuzlukları ve performans iyileştirme fırsatlarını tespit eder.</p><h3>OpenAI Code Review Extension Entegrasyonu</h3><h4>1. OpenAI API Erişimi Alın</h4><p>İlk olarak, <strong>OpenAI’nin API</strong>’sine erişim sağlamalısınız. Bunun için OpenAI’nin <a href="https://openai.com/">resmi web sitesinden</a> bir hesap oluşturabilir ve <strong>API anahtarınızı</strong> alabilirsiniz.</p><h4>2. Azure DevOps Agent oluşturma</h4><p>Ajanlar, <strong>Azure DevOps</strong>’un sürekli entegrasyon (<strong>CI</strong>) ve sürekli teslimat (<strong>CD</strong>) süreçlerini çalıştırmak için <strong>yerel bir makineye veya sanal makineye</strong> yüklenir. Bu ajanlar görevleri bir iş (job) olarak alır ve onları çalıştırır, sonrasında sonuçları <strong>Azure DevOps</strong>’a raporlar. Bizim yaratacağımız ajan ise yeni bir pull request açıldığı zaman <strong>koddaki değişiklikleri</strong> alıp <strong>OpenAI’a</strong> iletecek. Ardından <strong>yapay zekanın code review</strong>’den dönen iyileştirmelerini ilgili pull request altına yorum olarak ekleyecek.</p><p>Yaratacağımız ajanı Microsoft’un bulut ortamında veya kendi cihazımızda çalıştırabiliriz. Ben burda <strong>kendi cihazımda</strong> çalıştırmak istediğimden dolayı alttaki “<strong>Default</strong>” seçeneğini seçiyorum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HVsSMae2QXForKabkHRJEQ.png" /></figure><p>Ardından uygun işletim sistemini seçip agent dosyalarını indiriyorum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_R6EonrWlwlr_NmLCx7y_w.png" /></figure><p>Yeni bir klasör oluşturup dosyalarımı içine çıkarıyorum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XzNCKL7FN4hjN0p1Rxh1BA.png" /></figure><p>Ajanı özelleştirmek için aşağıdaki komutu kullanıyorum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ac2kcsdCb3dvtnGSs4RNrw.png" /></figure><p>Aşağıdaki görselde de görüldüğü üzere sizden istediği server URL alanına projenizin olduğu linki ekliyorsunuz (<a href="https://dev.azure.com/samisero">https://dev.azure.com/samisero</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*XOPJH_K4kK-EJqFlnezeOg.png" /></figure><p>Tokeni ise Azure DevOps üzerinden sağ üstteki profil kısmına tıklayıp ilgili sekmeden alıyoruz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*jg3WM4xxR-0be1PI5gjgZg.png" /></figure><h4>4. Pipeline oluşturma</h4><p>Pipeline oluşturmak için Azure DevOps üzerinde Pipeline sekmesine gelip <strong>Create Pipeline</strong> diyoruz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Dg1_dAfrQ1xUpBpjZzrbA.png" /></figure><p>Create Pipeline dedikten sonra bir <strong>yml</strong> dosyası oluşturacak. Yaml dosyaları sayesinde <strong>pipeline konfigürasyonu</strong> yapabiliyoruz. Aşağıdaki yml dosyasındaki dikkat edilmesi gerekenler.</p><ul><li>api_key: OpenAI üzerinden aldığımız <strong>api key</strong>’i buraya yazıyoruz.</li><li>ai_model: Burada size uygun olan yapay zeka modelini seçmeniz gerekiyor. “<strong>gpt-3.5-turbo</strong>” bizim senaryomuz için fiyat performans bir model. Ücretlendirme tablosuna <a href="https://openai.com/api/pricing/">buradan</a> ulaşabilirsiniz.</li><li>additional_prompts: Yapay zeka kodu review ederken nasıl bir gözle review istiyorsanız bu kısımda istediğiniz <strong>komutları</strong> girebilirsiniz.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*wt9y1Hjj1SCY6FIUsOFw3g.png" /></figure><h3>Örnek AI Code Review yorum 💬</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yQtt03cf7d_vJr8li9g62g.png" /></figure><h3>Entegrasyon sürecinde yaşadığım zorluklar 🤕</h3><p>OpenAI api’yi ilk aldığımda 5 dolar deneme limiti var ve 0 dolar kullanmışım gibi anladım aşağıdaki görselden. Meğerse 5 dolar hesabın limitiymiş yani 100 dolar bakiye yüklesem bile 5 dolarlık servis çağrısı yapabiliyormuşum. Bunu çözmek için OpenAI ile mailleşmelerim oldu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*abb-82wQZ9VfciN3Js1lag.png" /></figure><h3>Entegrasyon yaparken öğrendiklerim 🧠</h3><p>Bu süreçte en büyük kazanımım bir yml dosyası ile <strong>pipeline nasıl düzenlenir</strong> onu öğrendim. CI build süreçlerine dahil olmak DevOps tarafında da yetkinliğimi arttırdı.</p><h3>AI Code Review ile yeni akışımız 🔀</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N0aJ66uWsIV0m_qU21OExQ.png" /></figure><h3>Sonuç 🎯</h3><p>Yapay zeka tabanlı code review araçları, yazılım geliştirme <strong>sürecini hızlandıran ve kaliteyi artıran</strong> önemli bir araç haline gelmiştir. Geliştiricilere zaman kazandırırken, hata oranlarını azaltır ve kodun güvenliğini artırır. Ancak, bu araçların tam potansiyelini kullanabilmek için doğru şekilde yapılandırılmalı ve <strong>insan gözetimiyle</strong> birlikte çalışmalıdır.</p><p>AI&#39;nin yazılım dünyasında daha fazla yer almasıyla birlikte, <strong>code review süreçlerinin daha akıllı ve etkili</strong> hale gelmesi bekleniyor. Bu, yazılımcıların daha hızlı ve daha güvenli yazılımlar geliştirmelerine olanak tanırken, kod kalitesinin de sürekli olarak yükselmesini sağlayacaktır.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=076165bff93c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ibtech/13-ai-code-review-in-qnb-android-mobile-076165bff93c">12- AI Code Review in QNB Android Mobile📢</a> was originally published in <a href="https://medium.com/ibtech">IBTech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[State/Shared Flow and Channel]]></title>
            <link>https://medium.com/ibtech/state-shared-flow-and-channel-25b0906c4536?source=rss-a853e5e4a463------2</link>
            <guid isPermaLink="false">https://medium.com/p/25b0906c4536</guid>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[channel]]></category>
            <category><![CDATA[flow]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[serhat şamioğlu]]></dc:creator>
            <pubDate>Sat, 17 Jun 2023 21:05:49 GMT</pubDate>
            <atom:updated>2023-06-19T15:07:24.178Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*i7mBbivaeo4O9AARWNT2pA.png" /></figure><p><strong>StateFlow</strong></p><p>StateFlow is a state-holder observable flow. With the help of this feature, you can reach the state with .value property.</p><pre>// Define StateFlow<br>private val _stateFlow = MutableStateFlow(&quot;Default StateFlow Value&quot;)<br>val stateFlow = _stateFlow.asStateFlow()<br><br>// Set value<br>fun triggerStateFlow() {<br>    viewModelScope.launch {<br>        for (i in 1..7) {<br>             delay(1000L)<br>             _stateFlow.value = i.toString()<br>        }    <br>     }<br> }<br><br>// Collect value<br>lifecycleScope.launch {<br>    repeatOnLifecycle(Lifecycle.State.STARTED) {<br>        viewModel.stateFlow.collect {<br>            binding.textViewStateFlow.text = it<br>        }        <br>    }<br>}<br><br>// Reach StateFlow value<br>viewModel.stateFlow.value</pre><p><strong>SharedFlow</strong></p><p>SharedFlow does not keep the state so the best use case for this flow is one-time events. SharedFlow emits value even if there is no collector because It is a hot flow. Also, emitted values could collect from all its collectors.</p><pre>// Define SharedFlow<br>private val _sharedFlow = MutableSharedFlow&lt;String&gt;()<br>val sharedFlow = _sharedFlow.asSharedFlow()<br><br>// Emit value<br>fun triggerSharedFlow() {<br>        viewModelScope.launch {<br>            for (i in 1..7) {<br>                delay(1000L)<br>                _sharedFlow.emit(i.toString())<br>            }<br>        }<br>    }<br><br>// Collect value<br>lifecycleScope.launch {<br>            repeatOnLifecycle(Lifecycle.State.STARTED) {<br>                viewModel.sharedFlow.collect {<br>                    binding.textViewSharedFlow.text = it<br>                }<br>            }<br>        }</pre><p><strong>Channel</strong></p><p>Channel does not keep the state like SharedFlow. Again, the best use case for this flow is one-time events. But Channel is cold flow so it does not send value if there is no collector. Also, the channel could not collectable from different collectors.</p><pre>// Define Channel<br>private val _channelFlow = Channel&lt;String&gt;()<br>val channelFlow = _channelFlow.receiveAsFlow()<br><br>// Send value<br>fun triggerChannel() {<br>        viewModelScope.launch {<br>            for (i in 1..7) {<br>                delay(1000L)<br>                _channelFlow.send(i.toString())<br>            }<br>        }<br>    }<br><br>// Collect value<br>lifecycleScope.launch {<br>            repeatOnLifecycle(Lifecycle.State.STARTED) {<br>                viewModel.channelFlow.collect {<br>                    binding.textViewChannel.text = it<br>                }<br>            }<br>        }</pre><p><a href="https://github.com/serhatSamioglu/KotlinFundamentals/tree/master/app/src/main/java/com/example/kotlinfundamentals/flow">https://github.com/serhatSamioglu/KotlinFundamentals/tree/master/app/src/main/java/com/example/kotlinfundamentals/flow</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25b0906c4536" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ibtech/state-shared-flow-and-channel-25b0906c4536">State/Shared Flow and Channel</a> was originally published in <a href="https://medium.com/ibtech">IBTech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin Scope Functions]]></title>
            <link>https://medium.com/@serhatsamioglu35/kotlin-scope-functions-62f0669d842?source=rss-a853e5e4a463------2</link>
            <guid isPermaLink="false">https://medium.com/p/62f0669d842</guid>
            <category><![CDATA[kotlin-scope-functions]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[serhat şamioğlu]]></dc:creator>
            <pubDate>Sat, 18 Mar 2023 19:51:05 GMT</pubDate>
            <atom:updated>2023-03-18T20:45:14.274Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*xw5xXVj0sdd0uhUrU6JliQ.png" /></figure><p>Scope functions make code more <strong>clear and readable. </strong>They execute a block of code within the context of an object.</p><h4>Information you should know before we start</h4><p>Differences between these scopes are the way they <strong>refer to the context object</strong> and their <strong>return value</strong>.</p><p>There are <strong>two</strong> ways to refer to an object:</p><ol><li><strong>it</strong>: Accessing the context object as a receiver (it). It is better when the object is mostly used as an argument in function calls.</li><li><strong>this</strong>: Accessing the context object as a receiver (this). Recommended for assigning values to the properties of objects.</li></ol><p>Also there are <strong>two</strong> different return type:</p><ol><li><strong>context</strong>: Return the object itself, which is scoped.</li><li><strong>lambda: </strong>Return the last statement in the scope block.</li></ol><p>So you should consider carefully what return value you want based on what you want to do next in your code.</p><h3>Scopes</h3><ol><li>Let</li></ol><ul><li>The most common usage is null checks with safe call operator(?.)</li><li>‘let’ operation is performed on a object and return last statement in ‘let’ block. If there is no statement, it will return Unit by default like calling a function that has no return value.</li></ul><pre>fun main() {<br>    val animal = Animal(&quot;Max&quot;)<br><br>    animal.name?.let {<br>        print(&quot;The name of the Animal is: $it&quot;)<br>        // return unit by default because there is no return value.<br>    }<br><br>    val animalName = animal.name?.let {<br>        &quot;The name of the Animal is: $it&quot; // return this string.<br>    }<br>    print(animalName)<br>}<br><br>data class Animal(val name: String?)</pre><p>2. Apply</p><ul><li>The most common use case for ‘apply’ is for object configuration.</li><li>Apply returns the context object itself.</li></ul><pre>val intent = Intent().apply {<br>        putExtra(&quot;uri&quot;, &quot;https://www.linkedin.com/in/serhat-%C5%9Famio%C4%9Flu-2945b2173/&quot;)<br>    }<br>    // startActivity(intent)</pre><p>3. Run</p><ul><li>Equivalent to ‘apply’, but it returns the last line.</li></ul><pre>fun main() {<br>    val person = Person(24)<br><br>    val age = person.run {<br>        age = 25<br>        return@run age // you do not have to write return@run<br>    }<br>}<br><br>data class Person(var age: Int)</pre><p>4. With</p><ul><li>According to the Kotlin docs “with can be read as (<em>with this object, do the following.)</em>”.</li></ul><pre>fun main() {<br>    val human = Human(&quot;Serhat&quot;, 25)<br><br>    with(human) {<br>        print(&quot;Name length is : ${name.length}&quot;)<br>        print(&quot;Human age is : $age&quot;)<br>    }<br>}<br><br>data class Human(var name: String, var age: Int)</pre><p>5. Also</p><ul><li>It is used when we have to perform additional operations on already initialized object members.</li></ul><pre>val names = mutableListOf(&quot;Serhat&quot;)<br><br>    names.also { println(&quot;names list elements before adding new name: $it&quot;) }<br>        .add(&quot;Sami&quot;)</pre><p>Scope functions table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*90UW6uFAC69Mg3-HoxaPQw.png" /></figure><p>Reference: <a href="https://kotlinlang.org/docs/scope-functions.html">https://kotlinlang.org/docs/scope-functions.html</a></p><p>GitHub link: <a href="https://github.com/serhatSamioglu/KotlinFundamentals/tree/master/app/src/main/java/com/example/kotlinfundamentals/scopefunctions">https://github.com/serhatSamioglu/KotlinFundamentals/tree/master/app/src/main/java/com/example/kotlinfundamentals/scopefunctions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62f0669d842" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Coroutines]]></title>
            <link>https://medium.com/@serhatsamioglu35/coroutines-4da0908bc075?source=rss-a853e5e4a463------2</link>
            <guid isPermaLink="false">https://medium.com/p/4da0908bc075</guid>
            <category><![CDATA[kotlin-coroutines]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[serhat şamioğlu]]></dc:creator>
            <pubDate>Tue, 21 Feb 2023 19:20:42 GMT</pubDate>
            <atom:updated>2023-08-19T19:09:32.128Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*fnC9mdU1eibu7LCCfZ_7kg.png" /></figure><p>The Kotlin team defines coroutines as “lightweight threads”<br>They are sort of tasks that the actual threads can execute</p><p><strong>Scopes in Kotlin Coroutines</strong></p><p>1. Global Scope</p><p>Global Scope is one of the ways by which coroutines are launched.<br>When Coroutines are launched within the global scope, they live long as the application does. If the coroutines finish it’s a job, it will be destroyed and will not keep alive until the application dies.</p><p>2. LifeCycle Scope</p><p>All the coroutines launched within the activity also dies when the activity dies.</p><p>3. ViewModel Scope</p><p>Coroutine in this scope will live as long the view model is alive.</p><p><strong>Start a coroutine</strong></p><p>You can start coroutines in one of two ways:</p><p>1. Launch</p><p>Launch starts a new coroutine and doesn’t return the result to the caller. Any work that is considered “fire and forget” can be started using launch.</p><p>2. Async</p><p>Async starts a new coroutine and allows you to return a result with a suspend function called await.</p><p><strong>Dispatchers</strong></p><p>Kotlin coroutines use dispatchers to determine which threads are used for coroutine execution.</p><p>1. Dispatchers.Main</p><p>It is mostly used when we need to perform the UI operations within the coroutine.</p><p>2. Dispatchers.IO</p><p>This dispatcher is optimized to perform disk or network I/O outside of the main thread.</p><p>3. Dispatchers.Default</p><p>This dispatcher is optimized to perform CPU-intensive work outside of the main thread.</p><blockquote>Note: Also context could switch easily with the help of withContext function.</blockquote><pre>class CoroutinesActivity : AppCompatActivity() {<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.activity_coroutines)<br><br>        lifecycleScope.launch(Dispatchers.IO) {<br>            Log.d(&quot;testThread1&quot;, Thread.currentThread().name) // testThread1: DefaultDispatcher-worker-1<br>            val resultOfNetworkCall = simulateNetworkCall()<br>            withContext(Dispatchers.Main) {<br>                Log.d(&quot;testThread2&quot;, Thread.currentThread().name) // testThread2: main<br>                // update ui here<br>            }<br>        }<br><br>        lifecycleScope.launch(Dispatchers.IO) {<br>            val networkCallDeferred = async { simulateNetworkCall() }<br>            val networkCallResult = networkCallDeferred.await()<br>        }<br>    }<br><br>    private suspend fun simulateNetworkCall(): String {<br>        delay(3000L)<br>        return &quot;Network answer&quot;<br>    }<br>}</pre><p><a href="https://github.com/serhatSamioglu/KotlinFundamentals/blob/master/app/src/main/java/com/example/kotlinfundamentals/coroutines/CoroutinesActivity.kt">https://github.com/serhatSamioglu/KotlinFundamentals/blob/master/app/src/main/java/com/example/kotlinfundamentals/coroutines/CoroutinesActivity.kt</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4da0908bc075" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin Generics: in out type]]></title>
            <link>https://medium.com/@serhatsamioglu35/kotlin-generics-in-out-type-53745fbba83a?source=rss-a853e5e4a463------2</link>
            <guid isPermaLink="false">https://medium.com/p/53745fbba83a</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[generic-types]]></category>
            <dc:creator><![CDATA[serhat şamioğlu]]></dc:creator>
            <pubDate>Sat, 04 Feb 2023 23:53:34 GMT</pubDate>
            <atom:updated>2023-02-04T23:54:46.599Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Y5CCeAgiZSFiOXjaFG-slg.png" /></figure><p>When you declare a generic type with an in modifier,<br>That means functions can take M as arguments but they can’t return M</p><p>When you declare a generic type with an out modifier,<br>That means functions can return T but they can’t take T as arguments</p><pre>interface Production&lt;in M, out T&gt; {<br>    fun produceIn(input: M)<br>    fun produceOut(): T<br>}<br><br>class Product: Production&lt;Int, String&gt; {<br>    override fun produceIn(input: Int) {<br>        println(input.toString())<br>    }<br><br>    override fun produceOut(): String {<br>        return &quot;produceOut&quot;<br>    }<br>}<br><br>fun main() {<br>    val product = Product()<br>    product.produceIn(0)<br>    println(product.produceOut())<br>}</pre><p><a href="https://github.com/serhatSamioglu/KotlinFundamentals/blob/master/app/src/main/java/com/example/kotlinfundamentals/generics/InOutType.kt">https://github.com/serhatSamioglu/KotlinFundamentals/blob/master/app/src/main/java/com/example/kotlinfundamentals/generics/InOutType.kt</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53745fbba83a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Types of Kotlin classes]]></title>
            <link>https://medium.com/@serhatsamioglu35/types-of-kotlin-classes-dac8d11764dd?source=rss-a853e5e4a463------2</link>
            <guid isPermaLink="false">https://medium.com/p/dac8d11764dd</guid>
            <category><![CDATA[abstract-class]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[open-class]]></category>
            <category><![CDATA[sealed-classes]]></category>
            <category><![CDATA[data-class]]></category>
            <dc:creator><![CDATA[serhat şamioğlu]]></dc:creator>
            <pubDate>Sun, 29 Jan 2023 00:43:56 GMT</pubDate>
            <atom:updated>2023-02-04T23:43:08.403Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*bhUP7WIXJJ1w6AkowQInMQ.png" /></figure><h3>1-Data Class</h3><pre>/*<br>Some classes are designed to hold data. With data classes,<br>we can considerably reduce the boilerplate code.<br>Compiler automatically creates the equals, hashCode, toString, and copy functions.<br>*/<br><br>fun main() {<br>    val user = User(&quot;Serhat&quot;, 24)<br><br>    // Here we call the toString method, which has been created for us.<br>    val (name, age) = user<br>    println(&quot;$name $age&quot;)<br>}<br><br>data class User(val name: String, var age: Int)</pre><pre>Output -&gt; Serhat 24</pre><h3>2-Open Class</h3><pre>/*<br>Kotlin classes are final by default.<br>Other classes cannot inherit from a final class.<br>To make a class inheritable, we mark it with the open keyword.<br>*/<br>fun main() {<br>    val dog = Dog()<br>    dog.isOpenClass(false)<br>    dog.printMessage()<br><br>    val animal = Animal()<br>    animal.isOpenClass()<br>    animal.printMessage()<br>}<br><br>open class Animal {<br><br>    open fun isOpenClass(isOpen: Boolean = true) {<br>        println(&quot;isOpenClass: $isOpen&quot;)<br>    }<br><br>    fun printMessage() = println(&quot;message&quot;)<br>}<br><br>class Dog: Animal() {<br><br>    override fun isOpenClass(isOpen: Boolean) {<br>        super.isOpenClass(isOpen)<br>        println(&quot;override open fun&quot;)<br>    }<br>}</pre><pre>Output -&gt;<br>isOpenClass: false<br>override open fun<br>message<br>isOpenClass: true<br>message</pre><h3>3-Abstract Class</h3><pre>/*<br>* An abstract class, member, or member function is created with the abstract keyword.<br>* If a class inherits from an abstract class,<br>* it must implement all its abstract members and member functions.<br>* We cannot create an instance from an abstract class.<br>* Abstract classes are implicitly open,<br>* since they are useless if they don&#39;t have any concrete subclasses.<br>*/<br><br>fun main() {<br>    val teacher = Engineer(&quot;Serhat&quot;)<br>    teacher.displayAge()<br>}<br><br>abstract class Person(name: String) {<br>    init {<br>        println(&quot;Abstract class created. Person name is $name&quot;)<br>    }<br><br>    abstract fun displayAge()<br>}<br><br>class Engineer(name: String): Person(name) {<br>    private val age: Int = 24<br><br>    override fun displayAge() {<br>        println(&quot;Non-abstract class. Age is $age&quot;)<br>    }<br>}</pre><pre>Output -&gt;<br>Abstract class created. Person name is Serhat<br>Non-abstract class. Age is 24</pre><h3>4-Nested Class</h3><pre>/*<br>A nested class cannot access the members of the outer class.<br>*/<br>fun main() {<br>    val child = Root.Child()<br>    println(child.displayMessage())<br>}<br><br>class Root {<br>    class Child {<br>        fun displayMessage() = &quot;message&quot;<br>    }<br>}</pre><h3>5-Inner Class</h3><pre>/*<br>Unlike nested classes, they can access the members of their outer classes.<br>*/<br>fun main() {<br>    val innerClass = Outer().Inner()<br>    innerClass.displayOuterClassMessage()<br>}<br><br>class Outer {<br>    private val message = &quot;Outer class message&quot;<br><br>    inner class Inner {<br>        fun displayOuterClassMessage() = println(message)<br>    }<br>}</pre><h3>6-Sealed Class</h3><pre>fun main() {<br>    val circle = Shape.Circle(7f)<br>    val square = Shape.Square(5)<br>    val rectangle = Shape.Rectangle(8, 6)<br><br>    getArea(circle)<br>    getArea(square)<br>    getArea(rectangle)<br>}<br><br>sealed class Shape {<br>    class Circle(var radius: Float) : Shape()<br>    class Square(var width: Int) : Shape()<br>    class Rectangle(var width: Int, var height: Int) : Shape()<br>}<br><br>fun getArea(e: Shape) =<br>    when (e) {<br>        is Shape.Circle -&gt; println(&quot;Circle area is ${Math.PI * e.radius * e.radius}&quot;)<br>        is Shape.Square -&gt; println(&quot;Square area is ${e.width * e.width}&quot;)<br>        is Shape.Rectangle -&gt; println(&quot;Rectangle area is ${e.width * e.height}&quot;)<br>    }<br>// Sealed classes can have subclasses, but they must either be in the same file<br><br>sealed class Shape2<br>class Circle2(var radius: Float) : Shape2()<br>class Square2(var width: Int) : Shape2()<br>class Rectangle2(var width: Int, var height: Int) : Shape2()<br><br>fun getArea2(e: Shape2) =<br>    when (e) {<br>        is Circle2 -&gt; println(&quot;Circle area is ${Math.PI * e.radius * e.radius}&quot;)<br>        is Square2 -&gt; println(&quot;Square area is ${e.width * e.width}&quot;)<br>        is Rectangle2 -&gt; println(&quot;Rectangle area is ${e.width * e.height}&quot;)<br>    }</pre><p><a href="https://github.com/serhatSamioglu/KotlinFundamentals/tree/master/app/src/main/java/com/example/kotlinfundamentals/classes">https://github.com/serhatSamioglu/KotlinFundamentals/tree/master/app/src/main/java/com/example/kotlinfundamentals/classes</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dac8d11764dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dependency Injection-Koin]]></title>
            <link>https://medium.com/ibtech/dependency-injection-koin-207bf256228d?source=rss-a853e5e4a463------2</link>
            <guid isPermaLink="false">https://medium.com/p/207bf256228d</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[koin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[serhat şamioğlu]]></dc:creator>
            <pubDate>Thu, 21 Apr 2022 12:43:04 GMT</pubDate>
            <atom:updated>2023-02-04T23:39:38.832Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*kQ3sac-JpQYlLiKGNV3RzQ.png" /></figure><p>Selamlar,</p><p>Bu yazımda Dependency injection kütüphanelerinden birisi olan Koin’i anlatacağım.</p><h3>Dependency Injection ve Koin nedir ?</h3><p>Dependency injection, nesneler arası bağımlılığı azaltmayı hedefler bu sayede kod daha okunabilir bir hal alır ve nesneler arasındaki bağın azalmış olması test yazarken işimizi daha da kolaylaştırır. Koin ise bu bağımlılık yönetim işini modüller üzerinden yapar.</p><h4>Kavramlar</h4><ul><li>Modül tanımlaması yaparken <strong>module { }</strong> anahtar kelimesini kullanabiliriz.</li><li>Modül içerisinde oluşturacağımız bir instance için iki farklı tanımlama yapabiliriz. Bunlardan birisi <strong>single {} </strong>diğeri ise <strong>factory{}</strong>. Single ile bir instance yarattığımızda bu instance sadece bir kez yaratılır ve unique olur yani ikinci kez kullanmak istediğimizde ilk yaratılmış instance’ı bizimle paylaşır fakat Factory kullanımında ise instance her çağırıldığında yeniden yaratır.</li><li>Bilmemiz gereken diğer kavram <strong>get()</strong>. Modul içinde kullanacağımız get() fonksiyonları Koinin hangi class’a neyi enjekte edeceğini anlamasını sağlar.</li><li>Yaratmış olduğumuz modulleri <strong>startKoin(this, listOf(appModule)) </strong>diyerek içerisine androidContext ve modul listemizi vererek başlatabiliriz.</li></ul><h3>Dependency injection kullanmadan önce</h3><p>Aşağıdaki gibi bir class yarattığımızı düşünelim. Student class’ı Course ve Friend classlarını kullanıyor bunun içinde Student her yaratıldığında Course ve Friend classları da yaratılıyor. Fakat bu iyi bir yöntem değil çünkü Course ve Friend classları Student classına bağımlı hale gelmiş oluyor ve bu da yukarıda belirttiğim sebeplerden dolayı iyi bir şey değil. Bunun önüne geçmek için Course ve Friend classlarını Student classına enjekte etmemiz gerekiyor bu sayede aradaki bağımlılığı ortadan kaldırmış oluyoruz. Az sonra anlatacağım Koin kütüphanesi sayesinde bu kodu nasıl daha iyi bir hale getirebileceğimizi göstermeye çalışacağım.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dseti%26wt%3Dnone%26l%3Dauto%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%252520Student%2528%2529%252520%25257B%25250A%2525C2%2525A0val%252520course%25253A%252520Course%252520%25253D%252520Course%2528%2529%25250A%2525C2%2525A0val%252520friend%25253A%252520Friend%252520%25253D%252520Friend%2528%2529%25250A%2525C2%2525A0%25250A%2525C2%2525A0fun%252520doWork%2528%2529%25253A%252520String%252520%25253D%252520course.study%2528%2529%252520%25252B%252520%252522%25255Cn%252522%252520%25252B%252520friend.play%2528%2529%25250A%25257D&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dseti%26wt%3Dnone%26l%3Dauto%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%25252520Student%252528%252529%25252520%2525257B%2525250A%252525C2%252525A0val%25252520course%2525253A%25252520Course%25252520%2525253D%25252520Course%252528%252529%2525250A%252525C2%252525A0val%25252520friend%2525253A%25252520Friend%25252520%2525253D%25252520Friend%252528%252529%2525250A%252525C2%252525A0%2525250A%252525C2%252525A0fun%25252520doWork%252528%252529%2525253A%25252520String%25252520%2525253D%25252520course.study%252528%252529%25252520%2525252B%25252520%25252522%2525255Cn%25252522%25252520%2525252B%25252520friend.play%252528%252529%2525250A%2525257D&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca2153e3f02fec58cce670eba97f981a/href">https://medium.com/media/ca2153e3f02fec58cce670eba97f981a/href</a></iframe><h3>Koin kütüphanesinin kullanımı</h3><ol><li>İlk olarak Koin kütüphanesini projemize dahil etmemiz gerekiyor.</li></ol><ul><li>Gradle Scripts klasörü altında bulunan module düzeyindeki build.gradle dosyasımızı açıyoruz.</li><li>Dependencies içerisine Koin kütüphanemizi ekliyoruz <strong>implementation “org.koin:koin-android:2.0.1”</strong>.</li><li>Sağ üstte bulunan <strong>Sycn Now </strong>a basarak kütüphaneyi yüklüyoruz.</li></ul><p>2. Course ve Friend diye iki tane class oluşturuyorum.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dseti%26wt%3Dnone%26l%3Dauto%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%252520Course%252520%25257B%25250A%2525C2%2525A0fun%252520study%2528%2529%25253A%252520String%252520%25253D%252520%252522I%252520am%252520studying%252522%25250A%25257D%25250A%2525C2%2525A0%25250Aclass%252520Friend%252520%25257B%25250A%2525C2%2525A0fun%252520play%2528%2529%25253A%252520String%252520%25253D%252520%252522I%252520am%252520playing%252520with%252520my%252520friend%252522%25250A%25257D&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dseti%26wt%3Dnone%26l%3Dauto%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%25252520Course%25252520%2525257B%2525250A%252525C2%252525A0fun%25252520study%252528%252529%2525253A%25252520String%25252520%2525253D%25252520%25252522I%25252520am%25252520studying%25252522%2525250A%2525257D%2525250A%252525C2%252525A0%2525250Aclass%25252520Friend%25252520%2525257B%2525250A%252525C2%252525A0fun%25252520play%252528%252529%2525253A%25252520String%25252520%2525253D%25252520%25252522I%25252520am%25252520playing%25252520with%25252520my%25252520friend%25252522%2525250A%2525257D&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3557706f10487c9495899fa752c23ca8/href">https://medium.com/media/3557706f10487c9495899fa752c23ca8/href</a></iframe><p>3. Bir tane Student class’ı oluşturuyorum ve Course ve Friend classlarını parametre olarak almasını sağlıyorum. Burada anlaşılması gereken konu ise bu parametreleri ben yollamayacağım Koin benim için bu işi halledecek. Ben sadece modül içerisinde tanımlamalarımı yapacağım.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dseti%26wt%3Dnone%26l%3Dauto%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%252520Student%2528private%252520val%252520course%25253A%252520Course%25252C%252520private%252520val%252520friend%25253A%252520Friend%2529%252520%25257B%25250A%2525C2%2525A0%25250A%2525C2%2525A0fun%252520doWork%2528%2529%25253A%252520String%252520%25253D%25250A%2525C2%2525A0course.study%2528%2529%252520%25252B%252520%252522%25255Cn%252522%252520%25252B%252520friend.play%2528%2529%25250A%25257D&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dseti%26wt%3Dnone%26l%3Dauto%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%25252520Student%252528private%25252520val%25252520course%2525253A%25252520Course%2525252C%25252520private%25252520val%25252520friend%2525253A%25252520Friend%252529%25252520%2525257B%2525250A%252525C2%252525A0%2525250A%252525C2%252525A0fun%25252520doWork%252528%252529%2525253A%25252520String%25252520%2525253D%2525250A%252525C2%252525A0course.study%252528%252529%25252520%2525252B%25252520%25252522%2525255Cn%25252522%25252520%2525252B%25252520friend.play%252528%252529%2525250A%2525257D&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/54d60768b093090bb73d6a96d8a2f620/href">https://medium.com/media/54d60768b093090bb73d6a96d8a2f620/href</a></iframe><p>4. Bir tane appModule oluşturuyorum. İçerisinde singleton olarak Course tanımlıyorum ve factory olarak Friend tanımlıyorum. Ardından yine factory olarak Student oluşturuyorum. Single ve factory kullanırken seçimlerimi tamamen projeme uygun bir şekilde seçiyorum, ben bu proje için bir tane kurs olmasını istedim o yüzden singleton kullandım ama arkadaş ve öğrencilerin her seferinde yeniden yaratılmasını istediğimden dolayı factory kullandım, siz de projeye uygun seçimler yapabilirsiniz. Burda dikkat edilmesi gereken nokta Student içerisine get() fonksiyonunu kullanıyorum bu sayede Koin Course ve Friendi bizim için enjekte ediyor.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dseti%26wt%3Dnone%26l%3Dauto%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dval%252520appModule%252520%25253D%252520module%252520%25257B%25250A%2525C2%2525A0single%252520%25257B%252520Course%2528%2529%252520%25257D%252520%25252F%25252F%252520Course%252520singleton%252520olarak%252520tan%2525C4%2525B1mlanm%2525C4%2525B1%2525C5%25259Ft%2525C4%2525B1r%25250A%2525C2%2525A0factory%252520%25257B%252520Friend%2528%2529%252520%25257D%252520%25252F%25252F%252520Friend%252520factory%252520olarak%252520tan%2525C4%2525B1mlanm%2525C4%2525B1%2525C5%25259Ft%2525C4%2525B1r%25250A%2525C2%2525A0factory%252520%25257B%252520Student%2528get%2528%2529%25252C%252520get%2528%2529%2529%252520%25257D%25250A%25257D&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dseti%26wt%3Dnone%26l%3Dauto%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dval%25252520appModule%25252520%2525253D%25252520module%25252520%2525257B%2525250A%252525C2%252525A0single%25252520%2525257B%25252520Course%252528%252529%25252520%2525257D%25252520%2525252F%2525252F%25252520Course%25252520singleton%25252520olarak%25252520tan%252525C4%252525B1mlanm%252525C4%252525B1%252525C5%2525259Ft%252525C4%252525B1r%2525250A%252525C2%252525A0factory%25252520%2525257B%25252520Friend%252528%252529%25252520%2525257D%25252520%2525252F%2525252F%25252520Friend%25252520factory%25252520olarak%25252520tan%252525C4%252525B1mlanm%252525C4%252525B1%252525C5%2525259Ft%252525C4%252525B1r%2525250A%252525C2%252525A0factory%25252520%2525257B%25252520Student%252528get%252528%252529%2525252C%25252520get%252528%252529%252529%25252520%2525257D%2525250A%2525257D&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f069b366fec251446be87fea812fca99/href">https://medium.com/media/f069b366fec251446be87fea812fca99/href</a></iframe><p>5. Oluşturduğumuz modülü başlatmak için startKoin fonksiyonunu kullanmalıyız. Bu fonksiyonu kullanırken ilk parametre olarak androidContext’i vermeliyiz. İkinci parametreye ise modül listemizi aralarda virgül olacak şekilde yollamalıyız.</p><p><em>startKoin(this, listOf(appModule))</em></p><p>6. Modülümüzüde başlattığımıza göre artık Student objemizi yaratabiliriz. İki farklı şekilde obje oluşturma yöntemi var. Birincisi <strong>by inject()</strong> ile lazy kullanımı diğeri ise <strong>get()</strong> ile direkt setleyerek.</p><ul><li>by inject() kullanımında oluşturduğumuz obje lazy olarak yaratılacağından dolayı bu obje kullanılacağı zamana kadar tanımlanmaz.</li><li>get() kullanımında ise objeyi yarattığımız anda tanımlamasıda hemen yapılır.</li></ul><p><em>val student: Student by inject()<br>val student2 = get&lt;Student&gt;()</em></p><p>Örnek olması için iki farklı obje yaratma yönteminide kullandım. Yaratmış olduğumuz student ve student2 objelerine detaylıca bakacak olursak bu objelerin hafızadaki lokasyonları birbirinden farklı çünkü factory ile yaratıldı. Aynı şekilde friend objeleride öyle fakat iki student için course objelerinin hafıza lokasyonları aynı(16487) çünkü single ile yaratıldı.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6i2HpmVZ7gQiiiY9WQsU3g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*32PlBCq6xloqrhELrUE5DA.png" /></figure><p>Sonuç olarak Student objesini yaratırken içinde bulundurduğu course ve friend nesnelerini Koin kullanarak dışarıdan enjekte etmiş olduk bu sayede course ve friend nesnelerinin student ile olan bağımlılığını azalttık.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=207bf256228d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ibtech/dependency-injection-koin-207bf256228d">Dependency Injection-Koin</a> was originally published in <a href="https://medium.com/ibtech">IBTech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>