Object Oriented Programming Flashcards
An object
An instance of a class
How do you create a class
Class (Name):
(Here you would add attributes/characteristics e.g)
Features of a class
Methods, attributes,constructor
A constructor
A method that constructs objects (e.g the init method)
__init__(self):
Def __init__(self)
Constructor
What arguments need to be passed into the init method
The attributes you want to give an object
What do I have to put before each variable/attribute with the init method
Self.
(This is because they are the attributes relating to “self” the object)
If I wanted an attribute for my object such as hair how would it look in my constructor
Def __init__(self,hair):
Self.hair = hair
Instance variables
A variable which depends on the specific object (can be unique to particular object)
Class variables
A variable that is true to all objects of a class unless changed by calling the variable of an object or of the entire class
How does method chaining work?
Method chaining works by having multiple methods come after one another in a single line
Write a method chain for the object dog
With the first method being run and the next being bark
dog = Dog()
dog.run().bark()
What must be returned when method chaining?
Self
Super() or super function
Function used to give access to methods of a parent class. Returns a temporary object of a parent class when used.
How do you pass an object as an argument?
You put the object into the functions brackets 🤠