Object Oriented Programming (OOP) Flashcards
Define object.
An object is an instance of a class.
What is the need for self in classes?
self is used to reference the current instance of a class. It is used to access the attributes and methods of the class within its own definition.
Define attribute.
An attribute is a characteristic of an entity or object.
What is inheritance?
Inheritance is the retrieval of all the methods and attributes from a super class, so they can be used within a sub-class.
What is encapsulation?
Encapsulation is the bundling of attributes and methods together within a class. The attributes should only be accessed and modified by the classs own methods.
What is OOP?
OOP stands for Object-Oriented Programming. It is a way of coding that involves classes, objects, and methods.
Define method.
A method is an implementation of behavior inside a class.
What are static methods?
Static methods are methods that dont require instantiation or self. They can be relevant to the class, but may not require any of the attributes in the constructor method.
What is instantiation?
Instantiation is the process of creating a new instance of a class or an object.
What is an access modifier?
An access modifier is used in object-oriented programming to control the visibility of class attributes and methods. There are three types: public, protected, and private.
What is encapsulation?
Encapsulation is the bundling of attributes and methods together within a class, where a classs attributes should only be accessed and modified by its own methods (getters and setters). It ensures code security and efficiency.
What is the mantra of object-oriented programming?
The mantra of object-oriented programming is to favor composition over inheritance, program to interfaces rather than implementations, and ensure code security and usability for users.
What are getters and setters?
Getters are simple return statements used to retrieve attributes. Setters usually take in parameters and are used to modify attributes. They can also include validation.
Why should you encapsulate what varies?
Encapsulating what varies ensures that the code is accurate and representative of the desired blueprint. It also improves code security and efficiency. If something can change in any circumstance, it needs to be encapsulated to prevent potential issues.
What is overriding?
Overriding is where you have a method in the superclass and want it to behave differently in the subclass. It is a form of polymorphism.