<?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 Udara Jayasekara on Medium]]></title>
        <description><![CDATA[Stories by Udara Jayasekara on Medium]]></description>
        <link>https://medium.com/@udara98?source=rss-84a66b435b7a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0IuNJW8ta6unFQ_rfwTszg.jpeg</url>
            <title>Stories by Udara Jayasekara on Medium</title>
            <link>https://medium.com/@udara98?source=rss-84a66b435b7a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 18:39:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@udara98/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[KOA VS EXPRESS !]]></title>
            <link>https://udara98.medium.com/koa-vs-express-e13755daeae6?source=rss-84a66b435b7a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e13755daeae6</guid>
            <category><![CDATA[koa]]></category>
            <category><![CDATA[difference]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[express]]></category>
            <dc:creator><![CDATA[Udara Jayasekara]]></dc:creator>
            <pubDate>Sun, 06 Jun 2021 19:20:57 GMT</pubDate>
            <atom:updated>2021-06-06T19:20:57.237Z</atom:updated>
            <content:encoded><![CDATA[<h3>KOA VS EXPRESS !</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*ZPE_UAddppW4bYeGjhBr8w.png" /></figure><p>Koa and Express are flexible frameworks in Node.js .</p><p>As Koa is a significant departure from what most people know about Express, and because the design is fundamentally different, migrating from Express 3.0 to this Express 4.0 would practically entail rebuilding the entire application, we decided it would be better to build a new library.</p><p>Koa is a lightweight and adaptable Node.js framework with a small footprint. Express is free and open-source software, Koa also an open source framework developed and maintained by the creators of Express.js. Koa was created by the same team that created Express, with the goal of becoming a leaner, more expressive, and more robust basis for online applications and APIs.</p><p>To assist establish a better basis, Express goodies were relocated to the middleware level in Koa. This makes writing middleware for the full stack, not just the final application code, more pleasurable and less mistake. Many middleware would often re-implement comparable features, or worse, erroneously implement them, whereas features such as signed cookie secrets, among others, are often application-specific, not middleware-specific. Koa use the <strong>onion model.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*AX4TgT58wJ6yO4hZ2pn6FQ.png" /><figcaption>Koa Middleware</figcaption></figure><p>In Express, registering middleware is as simple as tying the middleware to the app object with the app.use() function.</p><p>In Koa, middleware registration is comparable to Express. The context object (ctx) replaces the request and response objects in Express, and Koa supports the contemporary async/await paradigm for building the middleware function.</p><h4>Way To Install..</h4><p>To begin creating with Koa and Express, you must first install Node and the node package manager (npm). If you don’t yet have them, go to Node installation to install node on your local machine.</p><p>Execute the following lines in your terminal to confirm that node and npm are installed.</p><pre><strong>$ node --version<br>$ npm --version</strong></pre><p>You can install npm − globally and locally, if you want to deal with development tools and CLI based packages, you must go with global package</p><pre><strong>$ npm install -g &lt;package-name&gt;</strong></pre><p>If you want to install frameworks and libraries, then go with local package.</p><pre><strong>$ npm install &lt;package-name&gt;</strong></pre><p>Just use following command to<strong> install Koa</strong> and include it in your package.json file.</p><pre><strong>$ npm install --save koa</strong></pre><p>NPM is used to install the Express framework globally so that it may be used to develop a web application using node terminal.</p><pre><strong>$ npm install express --save</strong></pre><h4>HELLO WORLD !!!</h4><p>After we’ve set up the development environment, it’s time to start working on our first <strong>Koa </strong>app.</p><p>Make a new file named app.js and paste the following code into it.</p><pre><strong>const koa = require(&#39;koa&#39;);<br>const app = new koa();<br><br>app.use(function* (){<br>   this.body = &#39;Hello world!&#39;;<br>});<br><br>app.listen(3000, function(){<br>   console.log(&#39;Server running on https://localhost:3000&#39;)<br>});</strong></pre><p>Following is a very basic <strong>Express </strong>app responds with Hello World!</p><pre><strong>const express = require(‘express’);<br>const app = express();</strong></pre><pre><strong>app.get(‘/’, function (req, res) {<br>  res.send(‘Hello World!’)<br>});</strong></pre><pre><strong>app.listen(3000, () =&gt; console.log(`App is listening on port 3000!`));</strong></pre><h3>Advantages</h3><p><strong><em>Koa</em></strong></p><p>Because of the framework’s versatility, Koa makes it easy to create middleware. It was intended to be pleasant to write as well as read. It also makes use of ES6 async/await features to avoid the need of callbacks. Another significant factor to consider is Koa’s minimal download footprint. With roughly 500 lines of code, it is incredibly light.</p><p><strong><em>Express</em></strong></p><p>Express takes extremely minimal boilerplate code to start up a server. Because of Express’s maturity and popularity, it is backed by significant documentation and an active community, so if you get confused, there are plenty of resources to assist you debug.</p><h3>Disadvantages</h3><p><strong><em>Koa</em></strong></p><p>While Koa is younger, it is also less reliable than Express. In addition, the open-source community is substantially smaller, which means there is less help accessible. Although async/await eliminates the requirement for callbacks, making many async calls at the same time might result in async/await hell. Also, Koa-specific middleware is incompatible with other frameworks.</p><p><strong><em>Express</em></strong></p><p>Fundamentally, it is a highly labor-intensive process. It necessitates developers manually creating all endpoints, which implies that the larger your code base, the more difficult it is to restructure. As a result, maintaining code requires a high level of organization because it is simple to become lost in all of the middleware. It also lacks the built-in error management that Koa has.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*_m-2dI7Y7-OVPPsPPw1xnw.jpeg" /><figcaption>Pros and Cons in Koa.js</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*e4OVzWqxCWUxDrbnCAalRw.jpeg" /><figcaption>Pros and Cons in Express.js</figcaption></figure><p>Actually important is that you select “the most important” for your business. Think about the performance of these frameworks and match them with your duty…</p><p><em>HAPPY CODING!!</em></p><p><strong>Resources</strong></p><p><a href="https://savvycomsoftware.com/express-koa-or-hapi-better-performance-with-the-right-nodejs-framework/">https://savvycomsoftware.com/express-koa-or-hapi-better-performance-with-the-right-nodejs-framework/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e13755daeae6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SOLID Principles with JAVA]]></title>
            <link>https://udara98.medium.com/solid-principles-with-java-48c2021100cb?source=rss-84a66b435b7a------2</link>
            <guid isPermaLink="false">https://medium.com/p/48c2021100cb</guid>
            <category><![CDATA[code-example]]></category>
            <category><![CDATA[pictures]]></category>
            <category><![CDATA[solid-principles]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[examples-of-java]]></category>
            <dc:creator><![CDATA[Udara Jayasekara]]></dc:creator>
            <pubDate>Sun, 07 Mar 2021 17:58:53 GMT</pubDate>
            <atom:updated>2021-03-08T03:01:14.743Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*jV8uSUlpXjwBMuUVdHPrtQ.png" /></figure><p>SOLID is formed from the first letters of the 5 major object-oriented design principles and act as an acronym. This was first raised in the <a href="https://web.archive.org/web/20150906155800/http:/www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf"><em>Design Principles and Design Patterns</em></a> 2000 essay paper <em>,</em>written by <strong><em>Robert C. Martin</em></strong> .</p><p>This makes development a bit difficult, but it’s not a waste of time considering the benefits. The main advantage of these principles is decreasing the dependencies while programming. Basically, these are also important for understanding, maintaining, and extending designs. Software developers can easily build up their software effectively, and efficiently.</p><p>Let’s start exploring what SOLID is..</p><h4>S- Single Responsibility principle</h4><h4>O- Open/closed principle</h4><h4>L- Liskov substitution principle</h4><h4>I- Interface segregation principle</h4><h4>D- Dependency inversion principle</h4><p><strong><em>REMEMBER </em></strong>— <em>The examples below are all with Java, but this works with other all Object-Oriented Programming Languages.</em></p><h3><strong>1)Single Responsibility principle</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4IwE057tOjvkacd4N2kB_w.jpeg" /></figure><p>Martin defined this principle in simple meaning as “a class should have one, and only one, reason to change.” Class has own duty to solve only one problem. With this principle classes are not much complex as it has few numbers of methods regarding one duty. if an error occurs, it will be easier to find and prevents unexpected side-effects of future changes with this situation.</p><p>Example given below also can implement logically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*nZBIktVodbo_6URX7AXFBg.png" /><figcaption>Student.java</figcaption></figure><p>But we can separate those responsibilities among new classes according to the SRP. Just think! Calculating GPA and the course Fee are not the responsibilities of Student class. We can build own classes to do those duties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*D4Ju-QZkXH6bNZ54GY6f6Q.png" /></figure><h3><strong>2)Open/closed principle</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IG64zkH0KqNP9DJID5Nk1Q.jpeg" /></figure><p>Martin recognized this principle as “You should be able to extend a class’s behavior without modifying it.”</p><p>When we think about this in simple way it says that this allows us to change what module is doing but at the same time we do not able to change binary or source codes(Modifications) .If You are familiar with OOP you should know polymorphism. When we are implementing interfaces, those classes have used this method to use as replacements for each classes. This method usually uses while implementing Inheritance with abstract classes and methods.</p><p>We can make the code maintainable and revisable by following this principle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*hQ-x7m_oK-xByfqAHw3RjA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*r5en5wBB0a8fT1LQiNd6ng.png" /></figure><p>Now the are method will simpler than before. This method can deal with any upcoming shapes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*jp4_3eSiNSaJq6I2L6pDcQ.png" /></figure><h3><strong>3)Liskov substitution principle</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bWc8iZiB-8SIiEQxp8QPLg.jpeg" /></figure><p>“Derived classes must be substitutable for their base classes.” is the definition given to this principle</p><p>Some have interpreted this as the hardest part to understand among these 5 principles. Just think about an animal. They all have the same appearance and behavior as their mother and father .This can be simply defined as the child class as a substitute for the parent class. According to this principle objects of a superclass should be replaceable with objects of its subclasses without breaking the application. Both classes should be having the same input parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*fXRV3P-gHWAGBjSzpSx73w.png" /></figure><p>Vehicles those who have Engine( Car, Van, Bus) can get access to the startEngine() method. when we consider about the bicycle it has no engine and it cannot override that. Then we want to refactor the Vehicle class as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*9fe5hTL5nfPjH_MlfCoGkg.png" /></figure><p>Separate classes for engine less vehicles and vehicles which have engines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*mIuZOoqBgVxFjJPsAgHb2A.png" /></figure><h3><strong>4)Interface segregation principle</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hhivx477ksHVVo6qO5fxEg.jpeg" /></figure><p>This principle says that “Make fine grained interfaces that are client specific.”</p><p>In real world scenarios we want to depend on the clients’ choice. Simply this says that if there are interfaces which do not need to implement the application, just ignore them, and do not depend on them. These unwanted interfaces are mentioned as “Fat Interfaces”. With this principle you have to separate an interface into highly cohesive interfaces (Role interfaces). This should be very important principle for java developers.</p><p>We can derive UniStudent Interface into role interfaces as Graduated and Undergraduate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*HqS7FKlWqlFP-rtEeQhqCA.png" /></figure><h3><strong>5)Dependency inversion principle</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q5JoaWhH0hXjfPxHomIRGw.jpeg" /></figure><p>If you are going to follow this principle you must “ Depend on abstractions, not on concretions.”</p><p>As a good java developer, you have to avoid using coupled codes. While we implement some methods loosely coupled codes makes better cords. According to this principle High level modules should not be depending on the Low-level modules. It just depends on the abstraction between two modules. Objects which are allocated to the modules are interconnect with an interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*I7Qip3a0c6hIjhe0oqAEyA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*kVpswUa55kjcaUpW1zzbtQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*Xgeb5VF5Iowstcz4K-x9UA.png" /></figure><p>Dependency Inversion principle Code-<a href="https://dzone.com/articles/solid-principles-dependency-inversion-principle"> https://dzone.com/articles/solid-principles-dependency-inversion-principle</a></p><p>KEEP LEARNING!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48c2021100cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>