OOP Flashcards
A programming model that is based on the concept of classes and objects.
Object-Oriented Programming (OOP)
T or F
OOP has no advantages over conventional or procedural style of programming.
F
OOP has several advantages over conventional or procedural style of programming.
Advantages of OOP?
- It provides a clear modular structure for the programs.
- It helps you adhere to the “don’t repeat yourself (DRY) principle, thus make your code much easier to maintain, modify and debug.
- It makes it possible to create methods with less code and shorter development time with high degree of reusability.
Why implement OOP?
- Good structure of the program
- Code reusability
- Faster development
- Easier to maintain
- Laravel implements OOP concepts
The two main aspects of OOP are:
Classes and Objects
A self-contained, independent collection of variables and functions which work together to perform one or more specific tasks.
Class
Individual instances of a class
Object
A class acts as _____ or _____from which individual objects can be created.
template / blueprint
T or F
When individual objects are created, they inherit the same generic properties and behaviors.
T
T or F
Each object cannot have different values for certain properties.
F
Each object may have different values for certain properties.
How do you declare a class?
- the class keyword
- the name of the class
- a pair of curly braces {}
Variables within a class are called ____, while functions are called ____.
properties, methods
Class names are also conventionally written in ____ i.e. each concatenated word starts with an uppercase letter (e.g. MyClass).
PascalCase
An OOP construct that is used to access contained properties and methods of a given object.
arrow symbol (->)
The pseudo-variable ____ provides a reference to the calling object.
$this
Allows to initialize the object’s properties upon creation of the object.
Constructor
We use _____ function to declare constructor inside the class.
__construct()
T or F
Constructor and destructor functions uses two underscores in declaration
T
Called when the object is destructed or the script is stopped or exited.
Destructor
T or F
__destruct function will be called at the beginning of the script.
F
__destruct function will be called at the end of the script.
T or F
Constructor is invoked automatically every time you create an object.
T
T or F
Destructor is invoked automatically every time you create a __destruct() function.
T
When working with classes, you can even restrict access to its properties and methods using the _________ for greater control.
visibility keywords (access modifiers)
A method can be accessed anywhere within or outside of class. Default in PHP
public