Giter Club home page Giter Club logo

student_data_inheritance's Introduction

Inheritance

A concept related to the object oriented approach of programming.

This file will demonstrate how inheritance allows child classes to adopt the methods and functionality available in its parent class and adding any additional functionality on top. This helps reduce the amount of duplicated code as it is bad practice to keep repeating yourself. According to the DRY acronym, "Do not repeat yourself."

devops_student [Parent/ Base Class]

  • Attributes
    • current_grade private
    • current_trainer public
  • Methods
    • print_details public
    • change_current_grade private

student_data [Child/ Derived Class]

The student_data class has actually not got any unique methods of attributes, for the purpose of demonstrating inheritance, the child class has been left empty. This demonstrates how it can use all the attributes and methods in its parent class.

To inherit from a parent class, you simply put it in the brackets of a classes declaration:
super().__init__ is taking all the members of the parent class and giving the child class access.

class DevOpsStudent(StudentData):  
    def __init__(self, current_grade, current_trainer):
        
        super().__init__(current_grade, current_trainer)
        self.current_grade = current_grade
        self.current_trainer = current_trainer

This is demonstrated in the parent classes file:
⚫ Here John is an instance of the DevOpsStudent class, it has taken two values that are assigned into the attributes it inherited from the parent class.
⚫ Secondly the parent classes method called print_details() has been called in this class even though it has not been created here, therefore it shows how inheritance is amazing when you want to allow classes to share attributes and methods.

John = DevOpsStudent(70, "Billy bog-man")

print(John.print_details())

student_data_inheritance's People

Contributors

johnbyrnejames avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.