7 Flashcards
(29 cards)
What is OOP?
Object-Oriented Programming (OOP) is a programming model based on the concept of classes and objects.
What are the advantages of OOP?
- Clear modular structure for programs
- Adheres to the DRY principle
- Easier to maintain, modify, and debug
- Allows for less code and shorter development time with high reusability
Why implement OOP?
- Good structure of the program
- Code reusability
- Faster development
- Easier to maintain
What are the two main aspects of OOP?
Classes and objects.
Define a class in OOP.
A class is a self-contained, independent collection of variables and functions that work together to perform specific tasks.
What is an object in OOP?
An object is an individual instance of a class.
How does a class act in OOP?
A class acts as a template or blueprint from which individual objects can be created.
What is the relationship between classes and objects?
Objects inherit the same generic properties and behaviors from their classes but may have different values for certain properties.
True or False: A class can be declared using the class keyword followed by the class name and curly braces.
True.
What are variables within a class called?
Properties.
What are functions within a class called?
Methods.
How are class names conventionally written?
In PascalCase, where each concatenated word starts with an uppercase letter.
What does the arrow symbol (->) do in OOP?
It is used to access contained properties and methods of a given object.
What is the purpose of the $this pseudo-variable?
It provides a reference to the calling object.
What is a constructor in OOP?
A constructor allows initializing the object’s properties upon creation.
How is a constructor declared in a class?
Using the construct() function with double underscores before ‘construct’.
What is a destructor in OOP?
A destructor is called when the object is destructed or when the script is stopped or exited.
How is a destructor declared in a class?
Using the destruct() function with double underscores before ‘destruct’.
What are access modifiers?
Keywords that restrict access to properties and methods for greater control.
List the three visibility keywords in OOP.
- public
- protected
- private
What does the public access modifier do?
Allows properties or methods to be accessed anywhere within or outside of the class.
What does the protected access modifier do?
Allows access only within the class itself or in inherited classes.
What does the private access modifier do?
Allows access only within the class that defines it.
What is inheritance in OOP?
Classes can inherit properties and methods from another class using the extends keyword.