<?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 Raj Dhakad on Medium]]></title>
        <description><![CDATA[Stories by Raj Dhakad on Medium]]></description>
        <link>https://medium.com/@rajdhakad?source=rss-7275ae30e8b1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KQXPFEXGSH-MVu92Sz6EnQ.jpeg</url>
            <title>Stories by Raj Dhakad on Medium</title>
            <link>https://medium.com/@rajdhakad?source=rss-7275ae30e8b1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 11:49:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rajdhakad/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[Pubg Avatar Privacy Policy]]></title>
            <link>https://medium.com/@rajdhakad/pubg-avatar-privacy-policy-2e41aebbe852?source=rss-7275ae30e8b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e41aebbe852</guid>
            <category><![CDATA[privacy]]></category>
            <dc:creator><![CDATA[Raj Dhakad]]></dc:creator>
            <pubDate>Tue, 13 Aug 2019 15:24:24 GMT</pubDate>
            <atom:updated>2019-08-13T15:24:24.633Z</atom:updated>
            <content:encoded><![CDATA[<h3>Privacy Policy</h3><p>VedSpace built the Pubg Avatar app as a Freemium app. This SERVICE is provided by VedSpace at no cost and is intended for use as is.</p><p>This page is used to inform visitors regarding our policies with the collection, use, and disclosure of Personal Information if anyone decided to use our Service.</p><p>If you choose to use our Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that we collect is used for providing and improving the Service. We will not use or share your information with anyone except as described in this Privacy Policy.</p><p>The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at Pubg Avatar unless otherwise defined in this Privacy Policy.</p><p><strong>Information Collection and Use</strong></p><p>For a better experience, while using our Service, we may require you to provide us with certain personally identifiable information, including but not limited to email. The information that we request will be retained by us and used as described in this privacy policy.</p><p>The app does use third-party services that may collect information used to identify you.</p><p>Link to the privacy policy of third party service providers used by the app</p><ul><li><a href="https://www.google.com/policies/privacy/">Google Play Services</a></li><li><a href="https://firebase.google.com/policies/analytics">Firebase Analytics</a></li></ul><p><strong>Log Data</strong></p><p>We want to inform you that whenever you use our Service, in a case of an error in the app we collect data and information (through third party products) on your phone called Log Data. This Log Data may include information such as your device Internet Protocol (“IP”) address, device name, operating system version, the configuration of the app when utilizing our Service, the time and date of your use of the Service, and other statistics.</p><p><strong>Cookies</strong></p><p>Cookies are files with a small amount of data that are commonly used as anonymous unique identifiers. These are sent to your browser from the websites that you visit and are stored on your device’s internal memory.</p><p>This Service does not use these “cookies” explicitly. However, the app may use third party code and libraries that use “cookies” to collect information and improve their services. You have the option to either accept or refuse these cookies and know when a cookie is being sent to your device. If you choose to refuse our cookies, you may not be able to use some portions of this Service.</p><p><strong>Service Providers</strong></p><p>We may employ third-party companies and individuals due to the following reasons:</p><ul><li>To facilitate our Service;</li><li>To provide the Service on our behalf;</li><li>To perform Service-related services; or</li><li>To assist us in analyzing how our Service is used.</li></ul><p>We want to inform users of this Service that these third parties have access to your Personal Information. The reason is to perform the tasks assigned to them on our behalf. However, they are obligated not to disclose or use the information for any other purpose.</p><p><strong>Security</strong></p><p>We value your trust in providing us your Personal Information, thus we are striving to use commercially acceptable means of protecting it. But remember that no method of transmission over the internet, or method of electronic storage is 100% secure and reliable, and we cannot guarantee its absolute security.</p><p><strong>Links to Other Sites</strong></p><p>This Service may contain links to other sites. If you click on a third-party link, you will be directed to that site. Note that these external sites are not operated by us. Therefore, we strongly advise you to review the Privacy Policy of these websites. We have no control over and assume no responsibility for the content, privacy policies, or practices of any third-party sites or services.</p><p><strong>Children’s Privacy</strong></p><p>These Services do not address anyone under the age of 13. We do not knowingly collect personally identifiable information from children under 13. In the case we discover that a child under 13 has provided us with personal information, we immediately delete this from our servers. If you are a parent or guardian and you are aware that your child has provided us with personal information, please contact us so that we will be able to do necessary actions.</p><p><strong>Changes to This Privacy Policy</strong></p><p>We may update our Privacy Policy from time to time. Thus, you are advised to review this page periodically for any changes. We will notify you of any changes by posting the new Privacy Policy on this page. These changes are effective immediately after they are posted on this page.</p><p><strong>Contact Us</strong></p><p>If you have any questions or suggestions about our Privacy Policy, do not hesitate to contact us at vedappsmail@gmail.com.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e41aebbe852" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mentor101 Privacy Policies!]]></title>
            <link>https://medium.com/@rajdhakad/mentor101-privacy-policies-376d62a27725?source=rss-7275ae30e8b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/376d62a27725</guid>
            <category><![CDATA[privacy]]></category>
            <dc:creator><![CDATA[Raj Dhakad]]></dc:creator>
            <pubDate>Sat, 06 Apr 2019 11:21:11 GMT</pubDate>
            <atom:updated>2019-04-06T11:21:11.573Z</atom:updated>
            <content:encoded><![CDATA[<h3>Privacy Policy</h3><p>VedSpace built the VedSpace app as an Ad-Supported app. This SERVICE is provided by VedSpace at no cost and is intended for use as is.</p><p>This page is used to inform visitors regarding our policies with the collection, use, and disclosure of Personal Information if anyone decided to use our Service.</p><p>If you choose to use our Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that we collect is used for providing and improving the Service. We will not use or share your information with anyone except as described in this Privacy Policy.</p><p>The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at VedSpace unless otherwise defined in this Privacy Policy.</p><p><strong>Information Collection and Use</strong></p><p>For a better experience, while using our Service, we may require you to provide us with certain personally identifiable information. The information that we request will be retained by us and used as described in this privacy policy.</p><p>The app does use third party services that may collect information used to identify you.</p><p>Link to privacy policy of third party service providers used by the app</p><ul><li><a href="https://www.google.com/policies/privacy/">Google Play Services</a></li><li><a href="https://support.google.com/admob/answer/6128543?hl=en">AdMob</a></li></ul><p><strong>Log Data</strong></p><p>We want to inform you that whenever you use our Service, in a case of an error in the app we collect data and information (through third party products) on your phone called Log Data. This Log Data may include information such as your device Internet Protocol (“IP”) address, device name, operating system version, the configuration of the app when utilizing our Service, the time and date of your use of the Service, and other statistics.</p><p><strong>Cookies</strong></p><p>Cookies are files with a small amount of data that are commonly used as anonymous unique identifiers. These are sent to your browser from the websites that you visit and are stored on your device’s internal memory.</p><p>This Service does not use these “cookies” explicitly. However, the app may use third party code and libraries that use “cookies” to collect information and improve their services. You have the option to either accept or refuse these cookies and know when a cookie is being sent to your device. If you choose to refuse our cookies, you may not be able to use some portions of this Service.</p><p><strong>Service Providers</strong></p><p>We may employ third-party companies and individuals due to the following reasons:</p><ul><li>To facilitate our Service;</li><li>To provide the Service on our behalf;</li><li>To perform Service-related services; or</li><li>To assist us in analyzing how our Service is used.</li></ul><p>We want to inform users of this Service that these third parties have access to your Personal Information. The reason is to perform the tasks assigned to them on our behalf. However, they are obligated not to disclose or use the information for any other purpose.</p><p><strong>Security</strong></p><p>We value your trust in providing us with your Personal Information, thus we are striving to use commercially acceptable means of protecting it. But remember that no method of transmission over the internet, or method of electronic storage is 100% secure and reliable, and we cannot guarantee its absolute security.</p><p><strong>Links to Other Sites</strong></p><p>This Service may contain links to other sites. If you click on a third-party link, you will be directed to that site. Note that these external sites are not operated by us. Therefore, we strongly advise you to review the Privacy Policy of these websites. We have no control over and assume no responsibility for the content, privacy policies, or practices of any third-party sites or services.</p><p><strong>Changes to This Privacy Policy</strong></p><p>We may update our Privacy Policy from time to time. Thus, you are advised to review this page periodically for any changes. We will notify you of any changes by posting the new Privacy Policy on this page. These changes are effective immediately after they are posted on this page.</p><p><strong>Contact Us</strong></p><p>If you have any questions or suggestions about our Privacy Policy, do not hesitate to contact us.</p><p>Email: vedappmail@gmail.com</p><p>This privacy policy page was created at <a href="https://privacypolicytemplate.net/">privacypolicytemplate.net</a> and modified/generated by <a href="https://app-privacy-policy-generator.firebaseapp.com/">App Privacy Policy Generator</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=376d62a27725" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python: The Complete inheritance Tutorial]]></title>
            <link>https://medium.com/@rajdhakad/python-the-complete-inheritance-tutorial-786b584475ea?source=rss-7275ae30e8b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/786b584475ea</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[inheritance]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Raj Dhakad]]></dc:creator>
            <pubDate>Fri, 28 Dec 2018 05:55:35 GMT</pubDate>
            <atom:updated>2018-12-28T06:09:35.303Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TkP7QgoMFMtpY9ddRbar2w.png" /></figure><p>What to do when objects are Alike? We gonna discuss in detail about all required concepts and their implementation. I am assuming you have basic knowledge of python and OOP. Even if you haven’t ever heard of inheritance or you have worked with it this tutorial should be helpful to you.</p><h3>Inheritance</h3><p>Let’s say I am creating a Schooling system some of the classes will be:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1e14b56de8bba9138ada89e921363c4/href">https://medium.com/media/b1e14b56de8bba9138ada89e921363c4/href</a></iframe><p>Ok, so both <strong><em>Person</em></strong> and <strong><em>Employee</em></strong> class share a lot of similar code, whenever in programming you find yourself duplicating the code you are doing it wrong.</p><p>So when objects are very similar to each other to follow DRY(Do not Repeat Yourself) principle we use <strong>inheritance</strong>(but not always).</p><p>As the name suggests inheritance refers to inheriting a class(i.e. it’s attributes and methods) by other class. Just like you inherit hair colour or eyes from your parents.</p><p>The class whose properties is being inherited is called <strong>Parent Class</strong>(or superclass) whereas the one which inherits called <strong>child class</strong>.</p><blockquote>We use inheritance when we have <strong><em>“is a”</em></strong> relationship between objects. Like, an employee is a Person, a car is a vehicle, a dog is an animal.</blockquote><p>Using inheritance on our previous example we have:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc3c758d359619f93fef3e675d1ddd39/href">https://medium.com/media/bc3c758d359619f93fef3e675d1ddd39/href</a></iframe><p>Ok, so what we did?</p><ul><li>To make <strong><em>Employee</em></strong> class child-class (or sub-class) of <strong><em>Person</em></strong> class we passed Person as a parameter to Employee. That’s how we inherit one class from other.</li><li>To access attributes and methods of parent class we use <em>super()</em><strong><em> </em></strong>method.</li><li>We know both objects are similar but not same. That’s why we extended parent class __init__ methods in child class <strong><em>Employee</em></strong> to add employee_id.</li><li>Since we didn&#39;t need to change the name method we haven’t override or extended it. We can directly access name method from <strong><em>Employee</em></strong> object.</li></ul><p>This is a basic example of Inheritance, no problem if you didn’t get everything as the tutorial progress you will.</p><blockquote>Everything is inherited</blockquote><blockquote>Well you may know everything in python is an object. Also all classes by default is inherited from built-in Object class implicitly (you didn’t need to write it).</blockquote><h3>Overriding attributes and Methods</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/829a4306f1ae3ceec2d00f794769593d/href">https://medium.com/media/829a4306f1ae3ceec2d00f794769593d/href</a></iframe><p>Well <em>override.py</em> says all.</p><h3>Extending Methods</h3><p>We have extended our <em>__init__</em> method in the previous examples. Let’s learn more about it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf3567e213f6e6e69685aa1fe2e09d0e/href">https://medium.com/media/bf3567e213f6e6e69685aa1fe2e09d0e/href</a></iframe><p>The output of the following code will be</p><pre><strong>bow bow<br>meow meow</strong></pre><p>This also goes with the real world, both cat and dog speak but differently.</p><p>This is a very simple example of method extending. The <em>__init__</em> method is a common use case of the method extending. Unlike method overriding we can use both parent class logic/code and additional code required by child-class by extending method. Thanks to <em>super()</em>.</p><h3>Multiple Inheritance</h3><p>A class may inherit properties from more than one class. You may have inherited your hairs from your Father and eyes from your Mother.</p><p>A simple example of Multiple Inheritance:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e216d3b9a10c3d8267348f7512e6bf3/href">https://medium.com/media/2e216d3b9a10c3d8267348f7512e6bf3/href</a></iframe><p>So, I don’t know why but we are creating a Robot which is similar to a Dog, that’s why we need to inherit it from both <strong><em>Robot</em></strong> and <strong><em>Dog class</em></strong>.</p><p>We have to use <em>&lt;class_name&gt;.__init__ </em>to initialize our <strong><em>RoboDog</em></strong> class with both parent classes (<strong><em>Robot</em></strong> and <strong><em>Dog</em></strong>) attributes and methods.</p><p>So we got a way to reference both parent class but what about methods. Since both <strong><em>Robot</em></strong> and <strong><em>Dog</em></strong> has a <em>walk()</em> method which one will be used?</p><p>When we search for an attribute in a class that is involved in python multiple inheritance, an order is followed. First, it is searched in the current class. If not found, the search moves to parent classes. It follows left to right order or depth-first. for ex. in RoboDog class Robot is passed first hence is more on the left side than Dog so it is ordered before Dog class.</p><p>This order is called Method Resolution Order (MRO). In our previous example order is:</p><ol><li>RoboDog</li><li>Robot</li><li>Dog</li><li>Object (built-in python class, all classes inherited from)</li></ol><p>i.e. Output of code is :</p><pre><strong>I am walking using my wheels</strong></pre><p>But what if for some crazy reason you want to use <strong>walk()</strong> method of Dog class on RoboDog object but you didn’t want to change the order of <strong>inheritance</strong>?</p><p>Just use this:</p><pre><strong>Dog.walk(Pika)</strong></pre><p>So, till now Multiple inheritance seems great but it’s considered as evil by many programmers. Java doesn’t even support multiple inheritance through classes. But there is another group of programmers which belief this widespread criticism of multiple inheritance is due to improperly implementation and usage of multiple inheritance. Python have really good approach towards multiple inheritance.</p><p>Now we gonna look at a common problem with multiple inheritance and how python solves it.</p><h3>The Diamond Problem</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*yVZr8-mi4VftBT35SMVlZw.png" /><figcaption>Diamond Inheritance problem | source: freecodecamp.org</figcaption></figure><p>This problem arises when a class is inherited from two base classes which themselves inherited from a class.</p><p>Following is a simple example of Diamond inheritance</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/160bb9a1cafb6d17201bff727da57846/href">https://medium.com/media/160bb9a1cafb6d17201bff727da57846/href</a></iframe><p>Output:</p><pre><strong>I am class C</strong></pre><p>This looks good so far. But this has a problem.if we want to use methods of the parent class we got some problem. See</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2436bfd709a34a9e6b4a0039bc0f842b/href">https://medium.com/media/2436bfd709a34a9e6b4a0039bc0f842b/href</a></iframe><p>The output of the following code:</p><pre><strong>I am Superclass<br>I am ClassA<br>I am Superclass<br>I am ClassB<br>I am ClassC<br>2 1 1 1</strong></pre><p>So, you can see <strong><em>Superclass</em></strong> is called twice. The reason is pretty simple, Both ClassA and ClassB call <strong><em>Superclass</em></strong> respectively.</p><p>Well, this is just a dummy example but in real applications, when we have classes with large data and use, this redundant call is very harmful.</p><p>Now obviously there is a workaround. But in most of the Object-oriented language, we have to write sophisticated code. I will not go in detail about the workarounds because python has a pretty simple solution to this problem with its Super method. well, literally super() method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ea8de42422c49e02678f087d02b868a/href">https://medium.com/media/2ea8de42422c49e02678f087d02b868a/href</a></iframe><pre><strong>I am Superclass<br>I am ClassB<br>I am ClassA<br>I am ClassC<br>1 1 1 1</strong></pre><p>So, a simple method solved the multiple inheritance problems. This shows how well-designed python is. But how? How python or super() method decides what to call and when to call. Remember MRO we talked about earlier? Yup, it helped us again. It is based on the “C3 superclass linearisation” algorithm. This is called a linearisation because the tree structure is broken down into a linear order.</p><p>It converts the inheritance tree into a list. We will not get into the detail of this algorithm in this tutorial but you can see the list using:</p><pre><strong>print(ClassC.mro())</strong></pre><p>Output:</p><pre><strong>[&lt;class &#39;__main__.ClassC&#39;&gt;, <br>&lt;class &#39;__main__.ClassA&#39;&gt;, <br>&lt;class &#39;__main__.ClassB&#39;&gt;, <br>&lt;class &#39;__main__.Superclass&#39;&gt;, <br>&lt;class &#39;object&#39;&gt;]</strong></pre><p>So first <strong><em>ClassC</em></strong> calls <strong><em>ClassA</em></strong>, then <strong><em>ClassA </em></strong>(rather than Superclass) calls <strong>ClassB</strong> and then <strong><em>ClassB</em></strong> calls <strong><em>Superclass</em></strong>.</p><blockquote>The algorithm uses the <em>next</em> method to call classes respectively. Also, ClassC calls ClassA first because ClassA is passed first to ClassC.</blockquote><h3>Multiple Inheritance Vs Composition</h3><p>Even though it’s easy to use mulitiple inheritance in Python, still it’s a complex concept. Very Often handling it is tricky, you have to remember the whole inheritance tree or waste your time looking what comes from where?</p><p>There a few design alternatives to multiple inheritance among which most prefered is composition.</p><p>Still, this is very subjective and depends on the usage. Both inheritance and Composition our fundamentals to OOP.</p><blockquote>Avoid multiple inheritance at all costs, as it’s too complex to be reliable. If you’re stuck with it,then be prepared to know the class hierarchy and spend time finding where everything is coming from.</blockquote><blockquote>Use inheritance only when there are clearly related reusable pieces of code that fit under a single common concept or if you have to because of something you’re using.</blockquote><blockquote>— Zed Shaw (Learning python the hard way)</blockquote><blockquote>The widespread prejudice that multiple inheritance is something “dangerous” or “bad” is mostly nourished by programming languages with poorly implemented multiple inheritance mechanisms and above all by improper usage of it.</blockquote><blockquote>— <strong>Bernd Klein (python-courses.eu)</strong></blockquote><blockquote>As a rule of thumb, if you think you need multiple inheritance, you’re probably wrong, but if you know you need it, you’re probably right.</blockquote><blockquote>— Dusty Phillips (Python 3 Object-oriented Programming)</blockquote><h3>Composition</h3><p>I know this tutorial is about inheritance, But we gonna discuss it’s the biggest rival composition because both patterns/concepts try to achieve the same.</p><p>Generally, we use Composition in a <strong><em>“has-a ”</em></strong> or <strong><em>“part-of” </em></strong>relationship. For eg. Book <em>has a</em> chapter, Car <em>has a</em> tank, the tyre is <em>part of</em> car</p><p>The idea behind Composition is fairly simple, Create an object of Class A inside Class B and use that object to access properties of class A inside Class B. Following example will make it more clear:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12d4dd2b0353da2746e855b49af415de/href">https://medium.com/media/12d4dd2b0353da2746e855b49af415de/href</a></iframe><p>Output:</p><pre><strong>Chapter 1: Welcome is taken from Best Book by RD from RD-pubs<br>RD<br>Best Book by RD from RD-pubs</strong></pre><p>All we did is Created a Book object (book_obj) inside class Chapter. Then we can access attributes and methods of Book class using Chapter class Object (first_chap).</p><blockquote>One thing to Note here is if we delete our chapter object, first_chap the book object will also be deleted. It’s justifiable in some cases but what if, you deleted <em>first_chap</em> from your Book <strong><em>Best Book</em></strong> to add another chapter say <em>zero_chap. We have </em><strong><em>Aggregation</em></strong><em> to take care of it.</em></blockquote><h4>Aggregation</h4><p>Aggregation is very similar to Composition, the difference is rather creating an object of Class A inside Class B, we first create an object of Class A separately and then pass it to Class B’s <em>__init__</em> method. Like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18d06d0639d90e2391e10ebabd270288/href">https://medium.com/media/18d06d0639d90e2391e10ebabd270288/href</a></iframe><p>Now even if we delete <em>first_chap</em> still we have our <em>book_obj</em> to add another <strong><em>Chapter</em></strong> object to it.</p><h4>Using Composition instead of Multiple Inheritance</h4><p>Well, till now we use Composition for a <em>has-a</em> relationship. Let’s use it as an alternative to multiple inheritance.</p><p>Going back to our RoboDog example Dog and Robot are the <em>part of</em> RoboDog’s characteristics or RoboDog <em>has </em>characteristics of Robot and Dog.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/988161c6dddd53425e34d47673dbf4eb/href">https://medium.com/media/988161c6dddd53425e34d47673dbf4eb/href</a></iframe><p>Output:</p><pre><strong>I am walking using my wheels<br>Bow Bow<br>Serve my Master</strong></pre><p>Composition decreases the complexity of the code and makes things easier to manage.</p><p>But, I will again say Composition vs Multiple-Inheritance is still subjective to your needs. Surely composition makes things easier but in some cases, you have to use Multiple-inheritance.</p><h3>Abstract Base Classes</h3><p>Abstract Base Class (or ABC because we like three-word acronym) is simply a class which just represent an abstract idea not it’s implementation. ABC class is like a template for other classes to use and follow. An instance/object of an ABC class can’t be created, nor it initializes also the sub-classes have to implement the methods of ABC class. Don’t worry the following example will make it clear.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/478cb7c66a76b87e0a1eec030c5e82ab/href">https://medium.com/media/478cb7c66a76b87e0a1eec030c5e82ab/href</a></iframe><p>Output:</p><pre><strong>25</strong></pre><p>Say we are creating a math-related software more specifically something which deals with shapes. We created a <strong><em>Shape</em></strong> class and defined some methods in it. Since different shapes have different properties we didn’t implement these methods rather just passed them for sub-classes like the <strong><em>Square</em></strong>.</p><p>The reason we do it is to make sure all instance(objects) of class Shape have area and perimeter methods. But this is not an abstract base class. Because we can create an object of <strong><em>Shape</em></strong> which nor makes sense nor goes with the definition of ABC classes. Also Square class didn’t have perimeter method still it works.</p><p>So how can we implement ABC class? well actually Python didn’t support Abstract class but, it has a module which does so. This module is called — for obvious reasons — abc.</p><h4>How to make an ABC class?</h4><p>We need to import <strong><em>ABC</em></strong> class and <em>abstractmethod</em> decorator from <em>abc</em> module, then inherit the required class from <strong><em>ABC </em></strong>class (<strong><em>Shape</em></strong> class in our example) and use <em>abstractmethod</em> decorator on methods you want sub-class to implement.</p><blockquote>You need at least one abstractmethod in ABC class, not all methods need to be an abstractmethod. Use abstractmethod decorated only on methods that must be implemented by sub-classes(like the Square class in our example must have area and perimeter methods).</blockquote><p>Now, let’s make Shape class an abstract base class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67bf45949c9ad005bbec00b1dfdfb6cc/href">https://medium.com/media/67bf45949c9ad005bbec00b1dfdfb6cc/href</a></iframe><p>Output</p><pre>...<br><em>shape_obj = Shape()<br>TypeError: Can&#39;t instantiate abstract class Shape with abstract methods area, perimeter</em></pre><p>See now, we got an error because we can’t create an object of ABC class. (<em>shape_obj = shape() </em>is invalid now).</p><p>Even if we remove <em>shape_obj = shape()</em> from <em>shape_is_abc.py</em> file, we will get this error</p><pre><em>square_obj = Square(5)<br>TypeError: Can&#39;t instantiate abstract class Square with abstract methods perimeter</em></pre><p>because we have two abstract methods area and perimeter but only one is implemented in the Square class.</p><p>The correct code will be:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/efc8e2f8a730f0725f020571d52907bc/href">https://medium.com/media/efc8e2f8a730f0725f020571d52907bc/href</a></iframe><p>Output:</p><pre><strong>25<br>20</strong></pre><h3>Conclusion</h3><p>We have talked about almost all major concepts related to inheritance. Thanks for reading the whole stuff. The objective of this tutorial is to explain concepts that’s why I used simple examples which may not resemble the real world programs. But this tutorial will definitely help you with inheritance, at least I hope so.</p><h4>Sources:</h4><p>Some of the sources I used as a reference and you can use to learn more about inheritance, OOP and python in general. :</p><p><a href="https://www.python-course.eu/">Python-Courses.eu</a></p><p><a href="https://www.packtpub.com/application-development/python-3-object-oriented-programming-third-edition">Python 3 Object-oriented Programming by Dusty Phillips</a></p><p><a href="https://www.youtube.com/channel/UCs6nmQViDpUw0nuIx9c_WvA">ProgrammingKnowledge Youtube channel</a></p><p><a href="http://www.stackoverflow.com/">StackOverflow</a></p><p><a href="https://www.programiz.com/">Programiz.com</a></p><p><a href="https://learnpythonthehardway.org/">Learning Python the Hard-way by Zed Shaw</a></p><p><strong>You can follow me or talk to me at:</strong></p><p><a href="https://twitter.com/rd_theofficial"><em>My twitter account</em></a><em> (it’s very new)</em></p><p><a href="https://github.com/rdcoder33"><em>My Github account</em></a></p><p>You can share your valuable feedbacks or queries in comments below and if you like to you can follow this Medium blog for more posts related to python, Django or may me programming in general.</p><p><em>Thank you!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=786b584475ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django Class-Based View explained]]></title>
            <link>https://medium.com/@rajdhakad/django-class-based-view-explained-b32c23885195?source=rss-7275ae30e8b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/b32c23885195</guid>
            <category><![CDATA[class]]></category>
            <category><![CDATA[views]]></category>
            <category><![CDATA[based]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Raj Dhakad]]></dc:creator>
            <pubDate>Fri, 26 Oct 2018 16:54:50 GMT</pubDate>
            <atom:updated>2018-10-26T16:59:25.503Z</atom:updated>
            <content:encoded><![CDATA[<h3>Django Class-Based View part-1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vj6zSOoC8UTc0gmsKLDs-A.jpeg" /><figcaption>Django class based views</figcaption></figure><p>So Class-Based Views(CBS) is like a nightmare for beginners in Django tho every one recommends using them because they help to organize code well and use object-oriented techniques like inheritance and promotes DRY(Do not Repeat Yourself) principle of programming. They are a little bit tricky but believe it’s not much hard to get with them, remembering the powers they provide.</p><p>The problem is there are not many great tutorials for CBS out there, they are few but most of them are out-dated and incomplete. In this blog series we gonna break down Class-Based Views and at the end of it, you will be able to implement Class-Based Views to your projects.</p><p>I am assuming to know the basics of Python and object-oriented programming, also the basics of Django like templates, URLs and you have written a few function-based views.</p><h3>Introduction to class-based views</h3><p>Function-based view:</p><pre><strong>from</strong> django.http <strong>import</strong> HttpResponse<br><br><strong>def</strong> my_view(request):<br>    <strong>if</strong> request.method == &#39;GET&#39;:<br>        # &lt;view logic&gt;<br>        <strong>return</strong> HttpResponse(&#39;Hello world&#39;)</pre><p>In class-based view, this will become:</p><pre># myapp/views.py<br><br><strong>from</strong> django.http <strong>import</strong> HttpResponse<br><strong>from</strong> django.views <strong>import</strong> View<br><br><strong>class</strong> MyView(View):<br>    <strong>def</strong> get(self, request):<br>        # &lt;view logic&gt;<br>        <strong>return</strong> HttpResponse(&#39;Hello world&#39;)</pre><ol><li>So in CBV, you need to import <em>View</em> class from<em> django.views</em>, then sub-class your view class from imported class.</li><li>And, the <em>request.method == ‘GET’</em>, changes to <em>get</em> method, i.e. to handle <strong>‘GET’</strong> methods in CBV we use <em>get</em> method.</li></ol><p>Now, since Django’s URL resolver expects to send the request and associated arguments to a callable function, not a class, class-based views have an <em>as_view</em> method which returns a function that can be called when a request arrives for a URL matching the associated pattern. i.e. while calling view in your URLs file use <em>as_view</em> method like shown below.</p><pre># urls.py</pre><pre><strong>from</strong> django.urls <strong>import</strong> path<br><strong>from</strong> myapp.views <strong>import</strong> MyView<br><br>urlpatterns = [<br>    path(&#39;about/&#39;, MyView.as_view()),<br>]</pre><blockquote>It is worth noting that what your method returns is identical to what you return from a function-based view, namely some form of <em>HttpResponse</em>. This means that <em>http shortcuts</em> or <em>TemplateResponse</em> objects are valid to use inside a class-based view.</blockquote><p>As we talked earlier class base views has some advantages over Function based views, let see some of those perks:</p><pre><strong>from</strong> django.http <strong>import</strong> HttpResponse<br><strong>from</strong> django.views <strong>import</strong> View<br><br><strong>class</strong> GreetingView(View):<br>    greeting = &quot;Good Day&quot;<br><br>    <strong>def</strong> get(self, request):<br>        <strong>return</strong> HttpResponse(self.greeting)</pre><p><em>GreetingView</em> is a simple CBV, which returns a greeting message <em>“Good Day”. </em>Now, what if we want to send greetings for morning rather writing a new view we can just override it in a sub-class.</p><pre><strong>class</strong> MorningGreetingView(GreetingView):<br>    greeting = &quot;Good Morning&quot;</pre><p>Another option is to configure class attributes as keyword arguments to the <em>as_view</em> call in the URLconf:</p><pre>urlpatterns = [<br>    path(&#39;about/&#39;, GreetingView.as_view(greeting=&quot;G&#39;day&quot;)),<br>]</pre><h3>Handling forms with class-based views</h3><p>A function-based view that handles forms may look something like this:</p><pre><strong>from</strong> django.http <strong>import</strong> HttpResponseRedirect<br><strong>from</strong> django.shortcuts <strong>import</strong> render<br><br><strong>from</strong> .forms <strong>import</strong> MyForm<br><br><strong>def</strong> myview(request):<br>    <strong>if</strong> request.method == &quot;POST&quot;:<br>        form = MyForm(request.POST)<br>        <strong>if</strong> form.is_valid():<br>            # &lt;process form cleaned data&gt;<br>            <strong>return</strong> HttpResponseRedirect(&#39;/success/&#39;)<br>    <strong>else</strong>:<br>        form = MyForm(initial={&#39;key&#39;: &#39;value&#39;})<br><br>    <strong>return</strong> render(request, &#39;form_template.html&#39;, {&#39;form&#39;: form})</pre><p>A similar class-based view might look like:</p><pre><strong>from</strong> django.http <strong>import</strong> HttpResponseRedirect<br><strong>from</strong> django.shortcuts <strong>import</strong> render<br><strong>from</strong> django.views <strong>import</strong> View<br><br><strong>from</strong> .forms <strong>import</strong> MyForm<br><br><strong>class</strong> MyFormView(View):<br>    form_class = MyForm<br>    initial = {&#39;key&#39;: &#39;value&#39;}<br>    template_name = &#39;form_template.html&#39;<br><br>    <strong>def</strong> get(self, request, *args, **kwargs):<br>        form = self.form_class(initial=self.initial)<br>        <strong>return</strong> render(request, self.template_name, {&#39;form&#39;: form})<br><br>    <strong>def</strong> post(self, request, *args, **kwargs):<br>        form = self.form_class(request.POST)<br>        <strong>if</strong> form.is_valid():<br>            # &lt;process form cleaned data&gt;<br>            <strong>return</strong> HttpResponseRedirect(&#39;/success/&#39;)<br><br>        <strong>return</strong> render(request, self.template_name, {&#39;form&#39;: form})</pre><p><strong>post</strong> method is like <em>request.method = post </em>expression of function-based view.</p><blockquote>NOTE: CBV view example must be looking longer than FBV example but when scaling up and adding more to your project CBV will make things much easier for you!</blockquote><p>Well, There are a lot more things CBV offers, such as mixins, built-in-generic-views and much more. And we will surely discuss them in the next part of this tutorial series. For now, this was your introduction to class-based views. Try creating few views to get comfortable with them. That will help you to understand advanced concepts.</p><h4>Key Takeaways</h4><ul><li>To define a class-based view first import a required class( like <em>View</em> class or generic views such as <em>TemplateView</em> or <em>ListView</em> that we will discuss later)</li><li>Then create a class, sub-class it from View and define your logic in that class</li><li><em>request.method == ‘GET’</em> or <em>request.method == ‘POST</em>’ can be used in class-based views by <em>get</em> and <em>post</em> methods.</li><li>Make sure to add as_view method while calling CBV in URLs pattern.</li></ul><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b32c23885195" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>