<?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 Chinonso Okoroafor on Medium]]></title>
        <description><![CDATA[Stories by Chinonso Okoroafor on Medium]]></description>
        <link>https://medium.com/@nonsookoroafor?source=rss-de3277125931------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Og8eGqLROiPdU33t</url>
            <title>Stories by Chinonso Okoroafor on Medium</title>
            <link>https://medium.com/@nonsookoroafor?source=rss-de3277125931------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 23:02:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nonsookoroafor/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[Authenticate Django Apps with Another Django App Hosted Separately]]></title>
            <link>https://python.plainenglish.io/authenticating-django-applications-with-another-django-app-hosted-separately-905949549fa2?source=rss-de3277125931------2</link>
            <guid isPermaLink="false">https://medium.com/p/905949549fa2</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[django-rest-framework]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Chinonso Okoroafor]]></dc:creator>
            <pubDate>Sun, 09 May 2021 06:50:42 GMT</pubDate>
            <atom:updated>2021-05-10T09:58:55.802Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GBNbShPx-QWqPhWTNR3P-A.jpeg" /><figcaption>Image source: soshace.com</figcaption></figure><p><em>Assumptions</em>: <em>I will be assuming you are familiar with the DjangoREST framework, Deploying on Heroku and SimpleJWT, and making use of environment variables in your Python code. I will also assume you already have your authentication service and other services that might want to be authenticated.</em></p><h4><strong>Use case</strong></h4><p>You have taken upon yourself the task to build an Authentication service for your company so you can implement a Single sign on(SSO). This means that every application you build for your company would be authenticated by that single Authentication service.</p><h4><strong>Challenge</strong></h4><p>Building your authentication service and other services to consume it is the easy part, one challenge you will encounter while trying to authenticate another service (Service B) using the authentication service, is getting a valid JWT that will be recognized by your Service B. This is as a result of the signing mechanism used by JWT.</p><p>Because every application has its own signing key that can only be recognized by the application that signed it, you will quickly run into trouble when you try using a token signed by a different application (Authentication service) in another of your service (Service B) hosted elsewhere.</p><h4><strong>Solution</strong></h4><p>Since we have identified Signing key as the problem, the question now is: how do we get Service B to recognize a token generated by our authentication service?</p><p>The whole magic happens, inside the <strong><em>settings.py</em></strong> files. The <em>SIMPLE_JWT </em>section of your <em>authentication service </em><strong><em>settings.py</em></strong> file should look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NNo0TALXL7PEe4hpqwQnTg.png" /><figcaption>Settings file for Authentication service</figcaption></figure><p>The two fields we are interested in the above image above are the <a href="https://django-rest-framework-simplejwt.readthedocs.io/en/latest/settings.html#signing-key">SIGNING_KEY</a> and the <a href="https://django-rest-framework-simplejwt.readthedocs.io/en/latest/settings.html#verifying-key">VERIFYING_KEY</a>. The values of these variables could be anything, but ensure it is something secure, you could use an online <a href="https://miniwebtool.com/django-secret-key-generator/">secret key generator</a> tool to generate unique values. In my case, I used the secret key of the application as my signing key, and verifying key. Next we modify the SIMPLE_JWT section in our <strong>settings.py</strong> file for Service B. It looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Cz819NQEuoUjAMt48ROHA.png" /><figcaption>Settings file for Service B</figcaption></figure><p>You can see that the configuration looks similar, but as the first image, we will focus on the last two variables. The value SERVICE_SECRET assigned to the SIGNING_KEY and VERIFYING_KEY is the value of the of the SIGNING_KEY in the Authentication service settings.</p><p>With this setup, your other Django applications will be able to make use of the token generated by the Authentication, and access its payloads. How you implement identifying the different services making a request to the Authentication service depends on personal preference, and beyond the scope of this writing.</p><h4><strong>Side Note</strong></h4><p>I will advise you change the signing key as often as possible, as your whole system might go down if it gets into the hands of unscrupulous folks.</p><p>Thank you for reading. I hope you have found this useful. Until next time, keep hacking!</p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=905949549fa2" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/authenticating-django-applications-with-another-django-app-hosted-separately-905949549fa2">Authenticate Django Apps with Another Django App Hosted Separately</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to deploy DjangoREST Application to Heroku]]></title>
            <link>https://python.plainenglish.io/how-to-deploy-djangorest-application-to-heroku-b3c9c9fe14eb?source=rss-de3277125931------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3c9c9fe14eb</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Chinonso Okoroafor]]></dc:creator>
            <pubDate>Tue, 16 Apr 2019 11:33:16 GMT</pubDate>
            <atom:updated>2021-05-11T11:37:25.382Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Deploy DjangoREST Application to Heroku</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tmZ8nrmKee4upo1o" /></figure><p>A couple of months ago, I was stuck deploying my DjangoREST app to Heroku. In the long run, my app was live but I traded something to achieve that. My documentation page was ugly, CSS was completely absent in my pages, and I literally pulled out my hair in frustration.</p><p>In this article, we will be going through the process of deploying DjangoREST applications to Heroku, and also ‘enable’ CSS on our pages. So sit back and enjoy the ride, probably with your favorite street musician playing in the background.</p><p>This article assumes you have your application all setup and hosted on Github, and you already have a Heroku account set up.</p><p><strong>Create an App on Heroku</strong></p><p>Login to Heroku and click on the new button on the top right-hand side</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rcbY1bIoMt6h9VXHlXmKlg.png" /></figure><p>Find the <strong>deployment method </strong>section and click on the Github icon to select repo you intend to deploy to Heroku</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lrlk4y8FCs2BtbQU340Rlw.png" /></figure><p>After you might have connected your application, you should enable automatic deploy, by choosing the Github branch you want to be deployed to Heroku after every push. In this example, I am using the master branch, which simply means that every push I make to the master branch will be automatically deployed.</p><p><strong>Create Procfile</strong></p><p>The next step is to create a file called Procfile, take note of the uppercase ‘P’, the Procfile helps to declare the commands that are run by your app on startup, Heroku needs to find this file in the root folder of your application. And typically, it contains a single line of code like this.</p><pre>web: gunicorn [App neme].wsgi</pre><p>Ensure that gunicorn is installed, this can be done by running the following command</p><pre>pip install gunicorn</pre><p><strong>Install Whitenoise</strong></p><p>Whitenoise allows your web application to serve its own static files, so how do we set that up? Firstly install whitenoise as shown below:</p><pre>pip install whitenoise</pre><p>Then go to the root folder of your application and create two folders, name them; <em>static</em> and <em>staticfiles</em>. These folders should not be empty as they are meant to hold all your static files, so for the sake of this article, we will add files we call <em>.dummyfile</em> to the static and staticfiles folder as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/184/1*UKXvRoT0UGyxZ2EZKylUEQ.png" /></figure><p>Now that we have our static files all setup, next we go to our application settings to make some configurations. First, we add whitenoise to our list of middleware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*V2Ons3JHsKowZRpM8t4Hgg.png" /><figcaption>Add whitenoise middleware to list of middlewares</figcaption></figure><p>Note that in the image above, <em>whitenoise.middleware.WhiteNoiseMiddleware </em>places just below the SecurityMiddleware. Next, make sure your STATIC_URL and STATIC_ROOT are properly set, this gives Django an idea of where to look for your static files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*raqpLga6bCjkub0zjlQsuQ.png" /><figcaption>Set static_url and static_root</figcaption></figure><p>Also, allow whitenoise to compress your static file by adding this alias</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*4MZ_5v3QpGac4zlB8llueA.png" /><figcaption>Whitenoise static files compression alias</figcaption></figure><p>Finally, create a <em>requirements.txt </em>file, and add all third-party installed apps, such as gunicorn to it. This can be done easily by running this command. Heroku needs this file to know and install all applications required to run your Django application.</p><pre>pip freeze &gt; requirements.txt</pre><p>Now commit your changes and push to your branch, wait a while for your app to build. Don’t forget to add the URL of your Heroku app to ALLOWED_HOST[] in the <em>settings.py </em>file</p><p>Now, go back to your Heroku dashboard and click on the open-app button on the top left side, you should see your application in all its beauty.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*fQZORCx-kCb7Qq46ESrPJw.png" /></figure><p>In this article, I explained how to push your DjangoREST application to Heroku while making sure your CSS still remains intact. Note that all processes described here also apply to traditional Django applications.</p><p>Please feel free to leave comments and observations. Till I write again, keep doing what you’re doing!</p><p><em>More content at </em><a href="http://plainenglish.io/"><em>plainenglish.io</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3c9c9fe14eb" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/how-to-deploy-djangorest-application-to-heroku-b3c9c9fe14eb">How to deploy DjangoREST Application to Heroku</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Java story: Abstract Classes and Methods]]></title>
            <link>https://nonsookoroafor.medium.com/my-java-story-abstract-classes-and-methods-3a6204f3231?source=rss-de3277125931------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a6204f3231</guid>
            <category><![CDATA[abstract-class]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Chinonso Okoroafor]]></dc:creator>
            <pubDate>Mon, 25 Mar 2019 18:53:16 GMT</pubDate>
            <atom:updated>2019-05-16T01:44:08.196Z</atom:updated>
            <content:encoded><![CDATA[<p>In my last post which can be found <a href="https://medium.com/@nonsookoroafor/my-java-story-visibility-modifiers-4368b1919c68">here</a>, I touched briefly on what subclasses in Java are. Today, we will be going a step further to achieving our Java pro status 💪. That brings up to the subject of Abstract classes and methods.</p><p>For this topic, we are going to assume you own a company and you decided to hire a personal assistant to help you with your ever-growing TODO list. You throw out a job advert and before you say Boom!!, you have made what you think is a great hire. Bravo!!!</p><p>On the first day at work, you make it clear to your new hire you don’t want to be a cranky boss who will keep looking over an employee’s shoulder every now and then. As you also do not need to spoon feed him as you are too busy to do that. So what do you do? You lay down a set of tasks he will be doing, what we call Job Description in the business world. This job description simply contains all you what is in the power of your new employee to do. Which includes tasks you OR the employee can do, and those you don’t want to touch at all, such as sorting of files, probably because they are boring 😒. taking notes that these job description only contains what the employee is meant to do and not HOW TO DO IT. You expect your new employee to take initiatives and remember your promise of not looking over his shoulders, remember?</p><p>The Job description you handed over to the employee on his first day is said to be <em>abstract</em>, because it contains tasks to do, but not HOW to do the tasks. Now, it is left for the employee to figure out the best way to do the tasks according to his work ethics and other unforeseen variables.</p><p>In Java, an abstract class is a class that contains abstract methods(unimplemented methods) which can be implemented by <em>concrete subclasses(proper classes)</em>. Using the illustration above, the job description is the abstract class, because it contains unimplemented methods. The only way the Java compiler can tell classes apart is that Abstract classes have a label to them signifying what they are.</p><pre>public <strong>abstract</strong> class JobDescription {}</pre><p>Let us go ahead to define some regular and abstract methods for our JobDescription abstract class. Create a <em>JobDescription.java</em> file.</p><pre>public abstract class JobDescription {<br>private int numberOfTask;<br>private int pendingTask;<br>private int doneTask;</pre><pre>// constructor<br>public JobDescription() {</pre><pre>}<br>public int getPendingTask() {<br>     return pendingTask;<br>}<br>public int getDoneTask() {<br>     return doneTask;<br>}<br>// now we define our abstract methods<br>public abstract String emailClient(String email);<br>public abstract boolean sortFiles();</pre><pre>}</pre><p>We then go ahead to create our <em>PersonalAssistant.java</em> file, where we implement the abstract methods <em>emailClient</em> and <em>sortFiles</em> declared above.</p><pre>public class PersonalAssistant <strong>extends JobDescription</strong> {<br>private boolean sortedFiles = false;</pre><pre>public String emailClient(String email) {<br>// code to send email to client with given number<br>     if(!email.isEmpty())<br>          return email;<br>     else<br>          return &quot;email is empty&quot;;<br>}</pre><pre>public boolean sortFiles() {<br>     if(sortedFiles)<br>          return true;<br>     else<br>          return false;<br> }<br>}</pre><p>The code above shows the implementation of the abstract methods declared in <em>JobDescription.java.</em> Note that the <em>PersonalAssistant.java</em> class <strong>inherits</strong> any method and variable exposed in the abstract JobDescription class, therefore, it is a subclass of JobDescription.This is explicitly stated by adding the <em>extends</em> keyword after the class declaration.</p><p>Now let us create objects to use our abstract class methods, create a file called <em>TestJobDescription.java and type in this</em></p><pre>public class TestJobDescription {</pre><pre>public static void main(String[] args) {<br><br>JobDescription assistant = new PersonalAssistant();</pre><pre>// first assistant calls methods<br>assistant.emailClient(&quot;nonso@nonso.com&quot;);<br>assistant.sortFiles();<br>  }<br>}</pre><p>What we have done in the code above is to create an object of PersonalAssistant. If you are familiar with classes and object creation, you should know too well that there is something strange with the way the assistant object was created above. Normally, it should be created thus:</p><pre>PersonalAssistant assistant = new PersonalAssistant()</pre><p>But because the PersonalAssistant is a subclass, it is created out of its superclass which in this case is the JobDescription class. There is a very important thing to note here. YOU CAN NOT CREATE AN OBJECT FROM AN ABSTRACT CLASS. This simply means you can not do something like this</p><pre>JobDescription description = new JobDescription()</pre><p>In the next post, we will be talking interfaces, don’t hesitate to leave a comment or questions. Till the next post, keep doing shit.✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a6204f3231" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My JAVA story: Visibility Modifiers]]></title>
            <link>https://nonsookoroafor.medium.com/my-java-story-visibility-modifiers-4368b1919c68?source=rss-de3277125931------2</link>
            <guid isPermaLink="false">https://medium.com/p/4368b1919c68</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Chinonso Okoroafor]]></dc:creator>
            <pubDate>Tue, 19 Feb 2019 17:59:36 GMT</pubDate>
            <atom:updated>2019-04-04T14:11:32.727Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GKGirEJ5-PaSz2bzGlRTjw.png" /><figcaption>Source: Google</figcaption></figure><p>This is Day one of my Java journey since I promised not to bore you out with some basics such as loops and variable declaration(you can pick them up from just any Java programming book, hopefully without issues), I will want to ask to be permitted to do something on <strong>visibility modifiers</strong>. For the Pythonic folks like me, this topic might look weird, since python doesn’t have an explicit way of declaring the visibility of objects.</p><p>So, in simple terms, visibility modifiers are ways Java ‘exposes’ variable and objects to other parts of the code. The language provides three access modifiers, they are; Public, Private and protected. There is a default modifier too(making it four) So we will go over this one after the other, and explain with codes how they work.</p><p><strong><em>Public</em></strong>: As the name implies, this modifiers allows every methods and data field in a class to be accessible from any package or class as long as an instance(object) of the class has been created. That may sound like gibberish, but let us grind some of the big jargon down.</p><blockquote><strong>Package</strong>:<a href="https://docs.oracle.com/javase/tutorial/java/concepts/package.html"> a package can be seen as similar to the different folders on your computer.</a></blockquote><blockquote><strong><em>Class</em></strong>: This is a blueprint of objects to be created, it defines the data and methods that will be needed by an object both for its initialization and manipulation. Let us be a bit more realistic using a real life example, it is the design of a house created on a piece of paper, from this single design, different units of houses can be built.</blockquote><blockquote><strong><em>Objects</em></strong>: This is also known as an instance. Like every real world object, they have state and behaviors which are defined while creating the template(class). Note that this states and behaviors can be modified (depending on the access specifier)</blockquote><p><strong>Private</strong>: Every data field or method declared with this access specifier can only be accessed by objects of the class it was created. Don’t worry, I will show an example of this specifiers, and hopefully, you appreciate them more.</p><p><strong>Protected</strong>: If a mum wants to mark a bag of orange, so her children can access it no matter where they find the bag of orange(be it Lagos or Owerri) they have access to it. She marks it as “protected”. In Java lingo, a child of a Class is called a <em>“subclass”</em>. No matter where the subclasses were created, be it in the same package or otherwise, they will be able to access any data field or method marked protected, while other objects can not.</p><p><strong>Default</strong>: Anytime a programmer fails to define a visibility modifier, Java automatically sets it to default. And the implication of this is that only objects of the class which contains the default variable, defined in the same package can access all the properties and methods ‘marked’ default in the class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*aaKVhbIo7N4E1DVoxQWWkg.png" /><figcaption><strong>source: Introduction to Java programming(Y Daniel Liang)</strong></figcaption></figure><p>I hope this diagram above helps to clarify all I have said up there, in my next post tomorrow, we will be taking another step further in the Java journey. Till then, keep doing shit.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4368b1919c68" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My JAVA journey: Intro]]></title>
            <link>https://nonsookoroafor.medium.com/my-java-journey-intro-b712f48cc432?source=rss-de3277125931------2</link>
            <guid isPermaLink="false">https://medium.com/p/b712f48cc432</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Chinonso Okoroafor]]></dc:creator>
            <pubDate>Mon, 18 Feb 2019 17:46:38 GMT</pubDate>
            <atom:updated>2019-04-04T14:09:28.666Z</atom:updated>
            <content:encoded><![CDATA[<h3>My JAVA story: Intro</h3><p>Hey guys!!!</p><p>I am about to start a journey and I want you all to tag along. So, I have to teach Java to people who have zero backgrounds in programming, or even struggling to wrap their heads around the concept of computer programs. Sure we all know starting a project like this is not an easy one when it comes to wiping up the discipline to carry on to the end. So I have decided to put myself ‘on the spot’ by publishing daily everything I learn/teach. I intend breaking down the contents as much as possible. Since teaching(writing) is two-way traffic, so I really expect to learn a lot from this and hope you do too.</p><p>The goal of this project is to develop quality Java programs using design patterns, unit testing, and developing web applications using the Spring framework.</p><p>Let&#39;s get it on!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b712f48cc432" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PYTHON OBJECT ORIENTED PROGRAMMING]]></title>
            <link>https://nonsookoroafor.medium.com/python-object-oriented-programming-18602eb1100e?source=rss-de3277125931------2</link>
            <guid isPermaLink="false">https://medium.com/p/18602eb1100e</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Chinonso Okoroafor]]></dc:creator>
            <pubDate>Sat, 06 Oct 2018 02:38:10 GMT</pubDate>
            <atom:updated>2019-04-04T14:16:03.475Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*MPEinqhx6YkmRD7QaiPvZA.png" /></figure><p>Have you ever wondered what the heck is Object Oriented Programming who in the world thought of making our lives miserable as programmers by coining such weird worlds? Yes, I had a bit of a headache wrapping my head around OOP initially, so I decided to write this post to explain object-oriented programming in Python from bottom up.</p><p>Let us pretend we don’t care about the fact that Alan Kay brought about the idea of OOP as we know today and let us dive straight into what he intended to achieve with such concept from the Python developer perspective.</p><p>OOP is a programming <em>paradigm</em> that models real-world objects, this is another way of creating representations of real-world entities inside your code. Properties and behaviors of real-world entities such as Bank accounts, employees, aircraft can be translated into software objects and that is what we will be looking at in this tutorial, so let us dive in!!!</p><p><strong><em>Python Classes</em></strong>: Classes are simply blueprints of objects to be created. It encapsulates the data and behavior of the object in question, so typically, you will need to create a single class for every object you want to model. Let us assume we want to create an aircraft class, it will be created like so:</p><pre>class Aircraft:<br>    pass</pre><p>The code snippet above simply creates an aircraft class and does nothing, but who want to create a class that does nothing? When creating a new class you assign some <em>‘default’</em> values to them, this can be done using the <em>“__init__”</em> method. This ensures that whenever a new object is created from that class(blueprint) those values you assumed in your <em>__init__ </em>method are assigned to the new object.</p><pre>class Aircraft:<br>    # initialize objects<br>    def __init__(self, type, capacity):<br>        self.type = type<br>        self.capacity = capacity<br>    def __repr__(self):<br>        return &quot;This is an aircraft&quot;</pre><p>In the snippet above, we defined an <em>__init__</em> method with the first argument being <em>‘self’</em>. Don’t be frightened, the <em>self </em>is simply a convention which keeps track of the uniqueness of every object created out of our Aircraft class, it is synonymous to <em>‘this’ </em>if you are coming from a JAVA family. It can be named anything, but we will follow the convention and call it <em>self</em>.</p><p>It is good practice to always have the __repr__ method in your class definition for the proper string representation of the class unless you don’t really mind seeing something like this &lt;__main__.Aircraft object at 0x7fc5993400b8&gt; below anytime you inspect your class</p><p>riting cool stuffsNow that we have created our Aircraft class, let us now create our objects</p><pre>a = Aircraft(&#39;fighter&#39;, 2)<br>b = Aircraft(&#39;passenger&#39;, 100)<br></pre><p>In the snippet above we created two instances of the class Aircraft, we can go ahead and compare this objects with the <em>is</em> and <em>==</em> operator and also access some of its attributes to see what we get</p><pre>&gt;&gt;&gt; a is b<br>&gt;&gt;&gt; False<br>&gt;&gt;&gt; a == b<br>&gt;&gt;&gt; False<br>&gt;&gt;&gt; a.type<br>&gt;&gt;&gt; fighter<br>&gt;&gt;&gt; b.capacity<br>&gt;&gt;&gt; 100</pre><p>Behind the scene when creating classes, Python makes use of the built-in <strong><em>type()</em></strong>, this is something you can take advantage of yourself when you need to create a class at runtime. Generally, Python takes the class namespace and passes it along with some other information to the built-in <strong><em>type()</em></strong> to instantiate the class. The information needed to instantiate a class are:</p><ol><li>The class name to be declared</li><li>The base class the defined class inherits from (In our case it is ‘object’)</li><li>The namespace dictionary populated when executing the class body</li></ol><p>Let us quickly see how we can create the Aircraft class above at runtime using the built-in <strong><em>type()</em></strong> function</p><pre>Aircraft = type(&#39;Aircraft&#39;, (object,)<br>                {&#39;type&#39;:&#39;fighter&#39;, &#39;capacity&#39;:2})</pre><pre># Now let us check the attributes of our new class<br>&gt;&gt;&gt; Aircraft.capacity<br>&gt;&gt;&gt; 2</pre><p>Phew!!! we should just leave Python OOP here for now as subsequently, I will be writing on class attributes, properties and also methods (bound, unbound, static, class and magic methods). Till then, keep doing shit.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18602eb1100e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>