Summary of my Object-Oriented Programming concepts
Some of the concepts we covered in Object-Oriented Programming include classes, instances, methods, inheritance, recursion, etc...
An object in programming is a unique instance of a data structure that's defined by its class. It comprises both data members (class variables or instance variables that holds data associated with a class and its objects) and methods. A Class is a concrete ADT (abstract data type) and a user-defined model for an object that defines a set of attributes that characterize any object of the class. The attributes are data members as well as methods, accessed via dot notation. A class variable is a variable that is shared by all instances of a class and are defined within a class but outside any of the class's methods. An instance variable a variable that is defined inside a method and belongs only to the current instance of a class. In general, an instance is an individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle. Class inheritance is when you create a class by deriving it from a preexisting class by listing the parent class in parentheses after the new class name instead of starting from scratch. The child class inherits the attributes of its parent class, and you can use those attributes as if they were defined in the child class. A child class can also override data members and methods from the parent. An object's attributes may or may not be visible outside the class definition. For these cases, you can name attributes with a double underscore prefix, and those attributes will not be directly visible to outsiders. Another kind of
Some Important Methods:
- __init__ ( self [,args...] ) Constructor (with any optional arguments)
- __del__( self ) Destructor, deletes an object
- __repr__( self ) Evaluatable string representation
- __str__( self ) Printable string representation
Some Important Functions:
- issubclass(sub, sup) boolean function returns true if the given subclass sub is indeed a subclass of the superclass sup
- isinstance(obj, Class) boolean function returns true if obj is an instance of class Class or is an instance of a subclass of Class