<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Charanraj</title>
    <description>The latest articles on Forem by Charanraj (@charanrajgolla).</description>
    <link>https://forem.com/charanrajgolla</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F19240%2F937ef339-a549-4fb1-a514-267508181d6e.jpg</url>
      <title>Forem: Charanraj</title>
      <link>https://forem.com/charanrajgolla</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/charanrajgolla"/>
    <language>en</language>
    <item>
      <title>JSON schema validation in Postman using external JSON files</title>
      <dc:creator>Charanraj</dc:creator>
      <pubDate>Mon, 05 Aug 2019 14:03:39 +0000</pubDate>
      <link>https://forem.com/charanrajgolla/json-schema-validation-in-postman-using-external-json-files-1jnc</link>
      <guid>https://forem.com/charanrajgolla/json-schema-validation-in-postman-using-external-json-files-1jnc</guid>
      <description>&lt;p&gt;Postman is an excellent tool for testing APIs. The response for an API call can be validated against a JSON schema to ensure that the values are valid in terms of type and format. In this article, we will explore how external JSON files can be loaded into Postman to avoid duplication of schema, in turn, making the tests more maintainable.&lt;/p&gt;

&lt;p&gt;Postman does not (as of v7.3.4) support the ability to reference external libraries and files. Which means that we will have to get the schema loaded in the environment variable to parse and use it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Primer on JSON schema &amp;amp; Tiny Validator library
&lt;/h2&gt;

&lt;p&gt;Before we begin, it would be wise to have some understanding of &lt;a href="https://json-schema.org/understanding-json-schema/"&gt;JSON schema&lt;/a&gt; and &lt;a href="https://geraintluff.github.io/tv4/"&gt;Tiny validator library&lt;/a&gt; which is used for the schema validation. For the purpose of demonstration, we have four entities Campaign, Media, Sponsor, and MediaType. Campaign requires an object of Media and optionally a Sponsor. Sponsor requires an object of Media.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vswsJnhO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1q1tci34cqgb6lc6sbqc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vswsJnhO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1q1tci34cqgb6lc6sbqc.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following are the schemas for the above-listed entities.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;common-schema.json&lt;/code&gt; — Contains the schema for common elements that are to be reused across the entire application&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;advertisement-schema.json&lt;/code&gt; — Contains schema for all elements corresponding to a module called advertisement in the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mF458ery--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/v0kmle7nkb08cgi636xg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mF458ery--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/v0kmle7nkb08cgi636xg.png" alt="Figure-1 common-schema.json"&gt;&lt;/a&gt;&lt;/p&gt;
Figure-1 common-schema.json



&lt;p&gt;View on GitHub: &lt;a href="https://gist.github.com/charanraj-golla/82bd2e51733cec512aab8f2d1e2713e0"&gt;https://gist.github.com/charanraj-golla/82bd2e51733cec512aab8f2d1e2713e0&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6m5PAaIq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/93fttos2rvohltxydaa6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6m5PAaIq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/93fttos2rvohltxydaa6.png" alt="Figure-2 advertisement-schema.json"&gt;&lt;/a&gt;&lt;/p&gt;
Figure-2 advertisement-schema.json



&lt;p&gt;View on GitHub: &lt;a href="https://gist.github.com/charanraj-golla/1823c488895c177c4c449c4cbc11c407"&gt;https://gist.github.com/charanraj-golla/1823c488895c177c4c449c4cbc11c407&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Following methods from tiny Validator can be used to validate the results from an API response:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;tv4.validate()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tv4.validateResult()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tv4.validateMultiple()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These methods accept four parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;data&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;schema&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;checkRecursion&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;banUnknownProperties&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first two are mandatory without which the validation won’t work. Passing &lt;code&gt;true&lt;/code&gt; for &lt;code&gt;checkRecursion&lt;/code&gt; will recursively validate the nested schema. Setting &lt;code&gt;banUnknownProperties&lt;/code&gt; to &lt;code&gt;true&lt;/code&gt; will result in a schema error if there are any additional properties apart from those which were defined in the schema. This is the bare minimum about this library that we must know for writing the tests.&lt;/p&gt;

&lt;p&gt;Next, we need to have some idea about &lt;code&gt;$ref&lt;/code&gt; and &lt;code&gt;$id&lt;/code&gt; keywords in JSON Schema. &lt;code&gt;$ref&lt;/code&gt; gets logically replaced with the thing that it points to. This referenced section can be within the same file or in an external file. The value of &lt;code&gt;$ref&lt;/code&gt; is a URI, and the part after &lt;code&gt;#&lt;/code&gt; sign (pound sign) is “the fragment” or “named anchor” and is in a format called JSON Pointer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jkHGKriU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/t4uatwled5rjqbocw079.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jkHGKriU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/t4uatwled5rjqbocw079.png" alt="Figure-3 The underlined section will be replaced with value for the key “sponsor”, available in the same file. Refer Figure-1 for details of the sponsor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next in line is the &lt;code&gt;$id&lt;/code&gt; property. The value of &lt;code&gt;$id&lt;/code&gt; is a URI that serves two purposes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It declares a unique identifier for the schema. (Figure-4)&lt;/li&gt;
&lt;li&gt;It declares a base URI against which &lt;code&gt;$ref&lt;/code&gt; URIs are resolved. (Figure-5)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;$id&lt;/code&gt; given to a subschema, in this case, the address provides a way to refer to subschema without using JSON Pointer. This means you can refer to them by a unique name as shown in the below example (Figure-4).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Pz6EooEK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/t14z0wzgse3mzorb09rk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Pz6EooEK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/t14z0wzgse3mzorb09rk.png" alt="Figure-4 Unique identifier in a schema."&gt;&lt;/a&gt;&lt;/p&gt;
Figure-4 Unique identifier in a schema.



&lt;p&gt;In the case where &lt;code&gt;$id&lt;/code&gt; is used to provide the base URI, a subschema present in the same file can be referenced as &lt;code&gt;"$ref" : "#/definitions/sponsor"&lt;/code&gt; which essentially means :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to the root of this document&lt;/li&gt;
&lt;li&gt;Find value with the key definition&lt;/li&gt;
&lt;li&gt;Within that object find the value of the key sponsor&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--W2w9uBJU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0i0b5s44yzknf53krdc0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--W2w9uBJU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0i0b5s44yzknf53krdc0.png" alt="Figure-6 Using JSON pointer"&gt;&lt;/a&gt;&lt;/p&gt;
Figure-6 Using JSON pointer



&lt;p&gt;Going back to our example, Media property in Campaign object expects an array of objects of the type Media. The schema for the array item must be specified against the items property. The schema for media is present in a separate file named common-schema.json (Figure-1). Here we are using absolute URI along with JSON pointer. The intent of using an absolute URI will be clear once we start writing the tests. Note that Postman does not make any network calls to the given URI.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Even though the value of a &lt;code&gt;$ref&lt;/code&gt; is a URI, it is not a network locator, only an identifier. This means that the schema doesn’t need to be accessible at that URI, but it may be. It is basically up to the validator implementation how external schema URIs will be handled, but one should not assume the validator will fetch network resources indicated in &lt;code&gt;$ref&lt;/code&gt; values.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Setup for validation
&lt;/h2&gt;

&lt;p&gt;The schema needs to be loaded into Postman’s environment variable before running tests for the collection. Include all schemas in the solution and add a controller for reading the schema files.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gMCQHGEY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/l56x7ektqws7skir00lg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gMCQHGEY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/l56x7ektqws7skir00lg.png" alt="Figure-7 Visual Studio solution setup"&gt;&lt;/a&gt;&lt;/p&gt;
Figure-7 Visual Studio solution setup




&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Add a folder to the collection right before any other requests are made and add requests to GetSchema action method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XrjKIBZi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/mv5ms74imd18eolg1iq1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XrjKIBZi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/mv5ms74imd18eolg1iq1.png" alt="Figure-8 Test setup in Postman"&gt;&lt;/a&gt;&lt;/p&gt;
Figure-8 Test setup in Postman



&lt;p&gt;In test tab for each request in the TestSetup folder, save the response to a unique environment variable. Paste the following code in the tests tab:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;This setup gives you full IDE support for editing the JSON files and saves the time you would have spent trying to edit the JSON string in the single-line text box every time there were changes are made to the schema.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yBRASgZb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8u8hu8o9bi5wct9g3hno.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yBRASgZb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8u8hu8o9bi5wct9g3hno.png" alt="Figure-9 Environment variable set after GET request was executed"&gt;&lt;/a&gt;&lt;/p&gt;
Figure-9 Environment variable set after GET request was executed



&lt;p&gt;Finally, in order to validate the schema, all the required schemas which are currently available in the environment variables (stored as a string) must be parsed to JSON and registered in the Tiny Validator. This can be done using &lt;code&gt;tv4.addSchema()&lt;/code&gt;. It accepts two parameters URI and schema object. An important point to note is that the URI used for registering the schema overrides the value specified for &lt;code&gt;$id&lt;/code&gt; key in the JSON file while registering the schema. This means that the URI you use to register the schema in &lt;code&gt;tv4.addSchema()&lt;/code&gt; function must be used while specifying the JSON pointer. When all the required schemas are registered using the &lt;code&gt;tv4.addSchema()&lt;/code&gt; function, any references in the schema will be automatically resolved.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;A response body similar to the one listed below would successfully pass the test.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V6hzzZ8o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/see5cka9eaaktojqtqb3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V6hzzZ8o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/see5cka9eaaktojqtqb3.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;tv4.validate()&lt;/code&gt; will stop at first error and return a false value. It would be ideal to have a list of all errors for a request. &lt;code&gt;tv4.validateMultiple()&lt;/code&gt; returns an array of validation result which can be iterated over to find the error details for a property. Remember to keep the console (Ctrl + Alt + C) window open when you are running the test.&lt;/p&gt;

&lt;p&gt;To verify if the schema validation really works as expected we can alter the response making it invalid. Value for alternateName in sponsor → media is changed to a number instead of a string and an unknown property called &lt;code&gt;aBadField&lt;/code&gt; is added as well.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The validation fails and the postman console logs the exact path and the cause of the error.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Hs-4irth--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/x6h8oornbcysebj0qndw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Hs-4irth--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/x6h8oornbcysebj0qndw.png" alt="Test fails due to invalid property values"&gt;&lt;/a&gt;&lt;/p&gt;
Test fails due to invalid property values



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yGHQnDN_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/f53af6q4yf4bj4gyqhih.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yGHQnDN_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/f53af6q4yf4bj4gyqhih.png" alt="Exact path of error logged in Postman console"&gt;&lt;/a&gt;&lt;/p&gt;
Exact path of error logged in Postman console



&lt;p&gt;Hope this post saves you some time while testing your APIs. I would appreciate your constructive feedback in improving this post. Got any handy tips on validating the APIs? Let's discuss :)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This article was originally published on &lt;a href="https://medium.com/skillhive/json-schema-validation-in-postman-using-external-json-files-2f3f0741800f"&gt;SkillHive Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>testing</category>
      <category>webdev</category>
      <category>postman</category>
      <category>api</category>
    </item>
    <item>
      <title>Programming for absolute beginners</title>
      <dc:creator>Charanraj</dc:creator>
      <pubDate>Sat, 14 Oct 2017 10:50:53 +0000</pubDate>
      <link>https://forem.com/charanrajgolla/programming-for-absolute-beginners-2hm</link>
      <guid>https://forem.com/charanrajgolla/programming-for-absolute-beginners-2hm</guid>
      <description>&lt;p&gt;Wanted to learn computer programming but not sure where to start? In this video series, I try to introduce you to basic concepts that you would find in almost any programming languages.&lt;br&gt;
There is no pre-requisite for this course. This course is independent of any programming languages and focuses purely on building up the required foundation to get you started with almost any programming language.&lt;br&gt;
We will be covering the following topics in this playlist:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is a computer program &amp;amp; how does it work?&lt;/li&gt;
&lt;li&gt;Abstract programming concepts — Pseudo code &amp;amp; Flowcharts&lt;/li&gt;
&lt;li&gt;Syntax — The rules of programming languages&lt;/li&gt;
&lt;li&gt;Working with data&lt;/li&gt;
&lt;li&gt;Program flow&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/charanrajgolla/beginners-guide---object-oriented-programming"&gt;Introduction to Object Oriented Programming [Article]&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/FMF-brcyo4Y"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a computer program &amp;amp; how does it work?
&lt;/h2&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/THJKX45Z36k"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Abstract programming concepts — Pseudo code &amp;amp; Flowcharts
&lt;/h2&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/AlEBMhxreo0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Syntax — The rules of programming languages
&lt;/h2&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/WZOUkttQHa0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Working with data
&lt;/h2&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/I8zR4TCmeZg"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Program flow
&lt;/h2&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/PsZEGba-sRA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This article was originally published on &lt;a href="https://medium.com/skillhive"&gt;Skill Hive Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>developer</category>
      <category>programming</category>
    </item>
    <item>
      <title>Beginner's guide - Object Oriented Programming</title>
      <dc:creator>Charanraj</dc:creator>
      <pubDate>Fri, 04 Aug 2017 17:09:26 +0000</pubDate>
      <link>https://forem.com/charanrajgolla/beginners-guide---object-oriented-programming</link>
      <guid>https://forem.com/charanrajgolla/beginners-guide---object-oriented-programming</guid>
      <description>&lt;p&gt;Complex real life requirements need to be model into instructions for the computer to understand. We have a few paradigms like Procedural Programming, Object oriented programming, Functional Programming etc. which can help in modeling the business requirements into computer programs. We will be learning about one such paradigm called Object oriented programming. OOP is a philosophy and is language neutral.&lt;/p&gt;

&lt;p&gt;We will be taking a look at the four concepts which act as the pillars for Object Oriented Programming. &lt;/p&gt;
&lt;ul&gt; &lt;li&gt;Abstraction&lt;/li&gt; &lt;li&gt;Encapsulation&lt;/li&gt;
&lt;li&gt;Inheritance&lt;/li&gt; &lt;li&gt;Polymorphism&lt;/li&gt; &lt;/ul&gt;

&lt;p&gt;Skip video and continue reading article&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/C4IoECB-grU"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a&gt; &lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Object Oriented Programming?
&lt;/h2&gt;

&lt;p&gt;Older programming languages like COBOL and C followed the Procedural Programming approach. The program written using these languages used to be a series of step by step instructions. They made use of procedures/subroutines for making the program modular. This programming paradigm focused on logic more than data and the program used to combine both of them together.&lt;/p&gt;

&lt;p&gt;Modern programming languages like Java, C# etc. follow the Object Oriented approach. In object oriented programming, importance is given to data rather than just writing instructions to complete a task. An object is a thing or idea that you want to model in your program. An object can be anything, example, employee, bank account, car etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Class, Object.. what's that?
&lt;/h2&gt;

&lt;p&gt;For getting started with object oriented programming we would have to know what is a class and object and the difference between them. A class is a blueprint for creating an object. It is similar to the blue print of a house. &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F58317pr3m4h3fbkz9bfu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F58317pr3m4h3fbkz9bfu.png" alt="Illustration of Class and Object" width="800" height="451"&gt;&lt;/a&gt;&lt;br&gt;
A class defines &lt;em&gt;attributes and behavior&lt;/em&gt;. If we are to model a car in our application then we could define attributes of the car like, model, fuel, make and behaviors like start, break, accelerate etc.. If you notice, the attributes and behavior that we are specifying are not specific to just one model of car. We are trying to generalize a car by stating that the car which we are going to model in our program will have these number of attributes and behavior.There might be others as well but our scope and interest for the business requirement are limited to these attributes. This helps us create a blue print of the car and later while we use this class for creating objects we create car objects with specific details.&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fk83oolqy85mixbnqra2w.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fk83oolqy85mixbnqra2w.PNG" width="643" height="429"&gt;&lt;/a&gt;&lt;br&gt;
Example, using the same class "Car" we can create different objects having variation in model, fuel type and make year while having the same common behavior.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;&lt;tr&gt; &lt;td&gt;&lt;table&gt;
&lt;tr&gt; &lt;th colspan="2"&gt;Object 1&lt;/th&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;Model&lt;/td&gt; &lt;td&gt;Volkswagen Polo&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;Fuel&lt;/td&gt; &lt;td&gt;Petrol&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;Make&lt;/td&gt; &lt;td&gt;2017&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td colspan="2"&gt;
Start()&lt;br&gt;Break()&lt;br&gt;Accelerate()
&lt;/td&gt; &lt;/tr&gt;
&lt;/table&gt;&lt;/td&gt; &lt;td&gt; &lt;table&gt;
&lt;tr&gt; &lt;th colspan="2"&gt;Object 2&lt;/th&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;Model&lt;/td&gt; &lt;td&gt;Volkswagen Vento&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;Fuel&lt;/td&gt; &lt;td&gt;Diesel&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;Make&lt;/td&gt; &lt;td&gt;2017&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td colspan="2"&gt;
Start()&lt;br&gt;Break()&lt;br&gt;Accelerate()
&lt;/td&gt; &lt;/tr&gt;
&lt;/table&gt; &lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In this way, Object oriented programming allows you to easily model real world complex system behavior. With OOP, data and functions (attributes and methods) are bundled together within the object. This prevents the need for any shared or global data with OOP, which is a core difference between the object oriented and procedural approaches.&lt;/p&gt;

&lt;h2&gt;
  
  
  Abstraction
&lt;/h2&gt;

&lt;p&gt;Abstraction lets you focus on what the object does instead of how it is done. The idea behind abstraction is knowing a thing on a high level. Abstraction helps in building independent modules which can interact with each other by some means. Independent modules also ease maintenance. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Abstraction means to represent the essential feature without detailing the background implementation or internal working detail.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We try to selectively focus on only those things that matter to us or in the case of programming, to our module. Modifying one independent module does not impact the other modules. The only knowledge one needs to know is what a module gives you. The person who uses that module does not need to bother about how the task is achieved or what exactly is happening in the background.&lt;/p&gt;

&lt;p&gt;Abstraction is everywhere. Everyday objects that we use has abstractions applied at various levels. One example is applying breaks in your car or bike. The breaking system is abstracted and you are provided with a paddle for stopping your vehicle. Making changes to acceleration system does not affect the braking system they are independent. You also do not have to bother about the internal working of the brakes, you only have to press the brake pedal and be it disc brake or drum brake, the vehicle stops.&lt;/p&gt;

&lt;h2&gt;
  
  
  Encapsulation
&lt;/h2&gt;

&lt;p&gt;The second concept Encapsulation is closely related to Abstraction. Encapsulation is all about exposing a solution to a problem without requiring the consumer to fully understand the problem domain.Encapsulation is binding the data and behaviors together in a single unit. This prevents the client or the user of the module from knowing about the inside view where the behavior of the abstraction is implemented.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhrbf0nhxw4i8hkqiy1ju.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhrbf0nhxw4i8hkqiy1ju.png" width="800" height="464"&gt;&lt;/a&gt; The data is not accessed directly. It is accessed through the exposed functions. Hiding the internalsÂ of the objectÂ protects its integrityÂ by preventing users from setting the internal data of the component into an invalid or inconsistent state.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Encapsulation isÂ not just about hiding complexity but conversely exposing complexity in a fail-safe manner.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Inheritance
&lt;/h2&gt;

&lt;p&gt;Inheritance is a powerful feature of Object oriented programming languages.Inheritance helps in organizing classes into a hierarchy and enabling these classes to inherit attributes and behavior from classes above in the hierarchy.&lt;br&gt;
Inheritance describes an “IS A relationship. This is how we talk in the real world. Example. A Parrot is a bird. US Dollar is a type of currency. But the phrase, Bank is a bank account is not correct. This relation is obvious when you try to describe some entity in the given business/problem statement.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6zfom9fjhu5lbdwpdkjn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6zfom9fjhu5lbdwpdkjn.png" width="800" height="413"&gt;&lt;/a&gt;&lt;br&gt;
With inheritance, you can define a common implementation/behavior and later for specialized classes you can alter or change it to something specialized. &lt;br&gt;
Inheritance does not work backward. The parent won’t have properties of the derived class.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Inheritance is a mechanism for code reuse and can help in reducing duplication of code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Do not force inheritance. You would just be writing unnecessary code. It is important to note that while trying to model the requirement don’t go adding multiple levels of inheritance. This is not needed. You need to try to identify common attributes and behavior in the entities you modeled and based on that you can go ahead re-factoring the code defining a suitable parent class. Common implementation can then be moved to this class.&lt;/p&gt;

&lt;h2&gt;
  
  
  Polymorphism
&lt;/h2&gt;

&lt;p&gt;Polymorphism is the concept that there can be many different implementations of an executable unit and the difference happen all behind the scene without the caller awareness.&lt;br&gt;
PolymorphismÂ allows computer systems to be extended with new specialized objects being created while allowing current part of the system to interact with a new object without concern for specific properties of the new objects. &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvfvvscp6sn8gtzwhcoyf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvfvvscp6sn8gtzwhcoyf.png" width="800" height="448"&gt;&lt;/a&gt;&lt;br&gt;
For example, if you needed to write a message on a piece of paper, you could use a pen, pencil, marker or even a crayon. You only require that the item you use can fit in your hand and can make a mark when pressed against the paper. So the action of writing would help you make a mark on the paper and what marking or writing instrument to use is a matter of decision.  Another example is a plane and space shuttle both can be termed as Flying objects. But the way both fly are different I.e. there is a difference in implementation. But from a viewer’s perspective both the objects can fly.&lt;/p&gt;

&lt;p&gt;Inheritance is one means of achieving polymorphism where behavior defined in the inherited class can be overridden by writing a custom implementation of the method. This is called method overriding also known as Run Time polymorphism.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F34ds8easmvozeszlkzi4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F34ds8easmvozeszlkzi4.png" width="669" height="505"&gt;&lt;/a&gt;&lt;br&gt;
There is also one more form of polymorphism called method overloading where inheritance does not come into the picture. The method name is same but the arguments in the method differ.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcr5eig6ibhfhgnebepdx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcr5eig6ibhfhgnebepdx.png" width="709" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Need help in understanding any technical topics? Send in your requests using the following link and I will try to make a post/video for it.&lt;br&gt;
&lt;a href="http://bit.ly/RequestCourse" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="http://bit.ly/RequestCourse" rel="noopener noreferrer"&gt;http://bit.ly/RequestCourse&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;References:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;https://stackoverflow.com/questions/16014290/simple-way-to-understand-encapsulation-and-abstraction&lt;/li&gt; &lt;li&gt;http://www.adobe.com/devnet/actionscript/learning/oop-concepts/polymorphism-and-interfaces.html&lt;/li&gt; &lt;li&gt;https://stackoverflow.com/questions/3322318/explain-polymorphism?rq=1&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Credit:&lt;br&gt;
Icons from &lt;a href="http://www.freepik.com/" rel="noopener noreferrer"&gt;http://www.freepik.com/&lt;/a&gt; &lt;/p&gt;

</description>
      <category>oop</category>
      <category>beginners</category>
      <category>concepts</category>
    </item>
    <item>
      <title>Learning from the top 10 mistakes developers make</title>
      <dc:creator>Charanraj</dc:creator>
      <pubDate>Thu, 18 May 2017 18:10:48 +0000</pubDate>
      <link>https://forem.com/charanrajgolla/learning-from-top-10-mistakes-done-by-developers</link>
      <guid>https://forem.com/charanrajgolla/learning-from-top-10-mistakes-done-by-developers</guid>
      <description>&lt;p&gt;I present to you a list of a few common mistakes new devs (and sometimes even experienced) usually do. I believe that learning from these mistakes would be of some help to you. So, here is my pick of the &lt;strong&gt;Top 10 mistakes&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Trusting user’s input
&lt;/h2&gt;

&lt;p&gt;Never trust the inputs provided by the end user. Also don’t blame them, mostly they do it unintentionally. We all make &lt;del&gt;mistake&lt;/del&gt; mistakes. This might not be of great concern to them but a piece of bad data could potentially bring down the application or cause compliance related issues. Apart from naive non-technical users we also have users with a certain level of technical know-how which they could potentially use to circumvent the system and get their work done. These are the users who pose a threat to your application and application needs to be safeguarded against the malicious activities.&lt;/p&gt;

&lt;p&gt;The only option to save from landing into trouble at a later stage is to build a strong validation with self-explanatory and human understandable error messages. Cryptic messages hardly help the naÃ¯ve user accomplish any task. Validation should be done in both &lt;strong&gt;user interface and database level&lt;/strong&gt; just to be sure that even if by some means front end validation was turned off the application still does not accept trash values.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Manual unit tests
&lt;/h2&gt;

&lt;p&gt;Code changes that you do, needs to undergo unit testing and further rounds of Quality Assurance testing. All tests or at least a few minimum number of tests needs to be done to ensure that the changes you made in one unit of code do not have side effects on the others. This is a necessary evil. Having &lt;strong&gt;automated unit tests and integration tests&lt;/strong&gt; save you a lot of manual efforts in validating side effects of the changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Skipping documentation
&lt;/h2&gt;

&lt;p&gt;The evilest thing that you can do is skipping documentation. Off course you can read the source code and try to understand the functionality. Reverse engineering the functionality from the code is a daunting task. This is good enough for a tiny functionality but definitely not a go for the entire application. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Requirement changes, code changes and more frequent - members of development team change."&lt;/em&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Knowledge about the application might not be transferred 100%. Sometimes people just forget. You need not create dozens of documents, create only a few like requirement specification and technical document and make sure to keep them &lt;strong&gt;updated&lt;/strong&gt;, this should be a part of a stringent process which needs to be followed at any cost and must be accommodated in the project planning. This would help at later stages when the application is in support/maintenance phase.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Forgetting about Audit and Error logging
&lt;/h2&gt;

&lt;p&gt;Not all end user/stakeholder would be bothered about cross cutting concerns like audit logs and error logging. A stakeholder would simply come with a one liner requirement which you would have to drill down till it becomes good enough to work on and deliver a solution addressing the stakeholder’s problem. &lt;/p&gt;

&lt;p&gt;Data change audit and error logging might never be a part of user’s requirement but is implicit that it needs to be maintained. One fine day user would simply approach support team and ask them to provide data related to access and roles or some business critical data required for compliance or audit purpose and then you would have nothing to share.&lt;/p&gt;

&lt;p&gt;Error logging is also crucial, you might do defensive coding but you never know what might fail in such cases effective error logging comes in handy. Monitoring error logs and trying to work on &lt;strong&gt;resolving recurring error&lt;/strong&gt; would help in making your application more stable.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Careless use of privileged access
&lt;/h2&gt;

&lt;p&gt;First and foremost, full control and access should never be provided. The system cannot protect itself from malicious activities if you leak the superuser or privileged account passwords. Risks involved in the &lt;strong&gt;reckless usage of privileged access&lt;/strong&gt; should be a part of learning for inexperienced new members of development or support team. There might be times when you would have to make a modification to production database and having privileged access can lead to many issues.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“With great power comes great responsibility”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I remember once unintentionally deleting data from the master table and the query was auto-committed. I went cold but soon realized I had taken backup of the data, phew! It is always good to provide limited access for data modification via an interface which keeps data backup. One should also note that this tool should also be capable of doing bulk operations, else you will find yourself doing manual updates for a very long time.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Configuration menace
&lt;/h2&gt;

&lt;p&gt;Scattered configurations in &lt;strong&gt;different files and database is a menace&lt;/strong&gt;. Change in a configuration which affects multiple applications would have to be replicated in many files and databases. This probably is not much of an issue if you have a handful of applications but would soon become an overwhelming task when you have hundreds of application in an enterprise environment. Moreover, naked passwords in config files are yet another threat. If configurations are database driven then it reduces the later hazels also safeguards sensitive configuration entries.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Hard-coded time bomb
&lt;/h2&gt;

&lt;p&gt;Hard coding values in the program are definitely a bad practice. Strange issues could occur because of the hardcoded value which silently sits there in your source code. One such incident is when you make use of hard-coded values for some maximum number, assuming that the maximum will not be hit. Such cases could take months or years to raise an error. Combined with no error logging and you will be in a very bad situation. Try to avoid hard-coded values. Move them to configuration variables if needed or try to completely avoid situations which would require them.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Prevent Burnouts
&lt;/h2&gt;

&lt;p&gt;Working continuously without any breaks will just lead to burnouts. &lt;strong&gt;You should always take breaks at regular intervals&lt;/strong&gt;. When you are overworked even doing simple things take a whole lot of time. &lt;/p&gt;

&lt;p&gt;Set small achievable milestones for yourself and don’t forget to reward yourself for it. Chocolates, cakes, quick games just about anything that makes you happy and feel free. Learning how to prevent burnouts will make you more productive.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Code / Suggest for building resume
&lt;/h2&gt;

&lt;p&gt;Having a strong resume with a listing of all new technologies is great but don’t just do it for &lt;strong&gt;inflating the resume&lt;/strong&gt;. Learn them but use them only if you see the benefit and high maintainability over the existing things. Sometimes adding new tech options would not even be required. &lt;/p&gt;

&lt;p&gt;Increasing the complexity should at least pay off in providing ease of maintainability. So I strongly believe that when you suggest some solution, check if it makes the application easy to maintain and makes everybody’s life easy.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Finding comfort zone in just one technology
&lt;/h2&gt;

&lt;p&gt;Being a ninja in one technology is awesome and is always beneficial. But don’t stay limited to one technology. Try to &lt;strong&gt;expand your knowledge&lt;/strong&gt;, sure there is a learning curve but challenging yourself helps you become a better technologist – a person who uses various technologies as effective tools and provides business enabling solution. &lt;/p&gt;

&lt;p&gt;Times change, technology may become obsolete but your &lt;strong&gt;learning should never stop&lt;/strong&gt;. Always try to explore new technologies and try weighing the pros and cons before using it as a solution for solving a problem.&lt;/p&gt;

&lt;p&gt;I would like to hear about your views on these points. If you have any experiences to share, go ahead and post a comment. Remember…&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The only real mistake is the one from which we learn nothing. ~ John Powell&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;This article was originally published on &lt;a href="https://medium.com/skillhive"&gt;SkillHive Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mistakes</category>
      <category>developer</category>
    </item>
  </channel>
</rss>
