OOP Flashcards
What is Object-Oriented Programming
Object-Oriented Programming is a programming paradigm that relies on the concepts of classes and objects, where you break a complex program down into objects that can communicate with each other
What are objects?
Objects are a collection of data and their behaviors.
Objects frequently represent real-world objects, BUT it is possible for objects to sometimes serve application logic and have no direct real-world parallels.
Examples: authentication, templating, request handling, etc
Where do these objects come from?
Classes
What is a class?
A blueprint for creating objects. the state of an object is modeled using variables in a class and the behavior is modeled using methods in the class
we will refer to the variables creating state for the class as properties we will refer to the defined behavior on the class as methods
What are properties?
properties are variables that contain information regarding the object class
What are methods?
methods are functions that have access to properties and other methods of a class
What are the benefits of using objects and classes?
Objects and classes are essential for compartmentalizing code. Different components can become separate classes that would interact through interfaces. These ready-made components will also be available for use in future applications.
Classes make it easier to maintain different parts of an application since it is easier to make the changes directly on the class
what is the syntax for creating a class?
MyClass:
pass
what is the syntax for instantiating an object from a class
obj = MyClass()
What is a class variable?
a class variable is a property defined in the class and is shared among all of the instances or objects of that class. A change to a class variable will the change the value of the property on all instances or objects of the class.
What is an instance variable?
an instance variable is a property unique to the instance or object of the class. A change in the instance variable will change the value of the property on that instance or object ONLY.
Where are class variables defined?
class variables are defined outside the initializer
Where are instance variables defined?
Instance variables are defined inside the initializer
How do you use class variables smartly?
Class variables are useful when implementing properties that need to be common and accessible to all class objects
What are the three types of methods in Python?
class methods, instance methods (most used method type in Python OOP), static methods
What is the purpose of a method?
a method is an interface between the program and the properties of a class in the program.
a method can alter the content of the properties or use the values of the properties to perform an operation in the program
What is a method?
a group of statements that performs some operation that may or may not return a result
a special note about method parameters
method parameters make it possible to pass values to the method. The FIRST method parameter should always be self.
the self argument only needs to be passed in in the method definition and not when the method is called
a special note about the return statement in methods
the return statement makes it possible to get the value from the method
What is method overloading?
method overloading refers to making a method perform different operations based on the nature of its arguments.