OOP Flashcards
What is Enumeration?
A type of class that creates a user-defined data type
Open Closed Principle
Classes can be extended, but not modified. It is violated if you will need to modify the class to handle an inheriting class
Abstract Class
Cannot instantiate an object but can only be used as a base class.
Composition
Form of association between classes where one class (the composite or whole) contains one of more objects of other classes (the components or parts).
What type of relationship does composition represent? As opposed to what?
“Has-a” - “Is-a”
Singleton Pattern
Ensures that a class has only one instance and provides a global point of access. Used when having multiple instances could lead to inconsistencies and management issues
Abstract Factory
Creational design pattern. Provides an interface for creating families of related or dependent objects without specifying their concrete classes.
Data Hiding
Refers to masking a classes internal operations and only providing an interface through which other entities can interact with the class without being aware of what is happening within.
Encapsulation
Use to achieve data hiding. Refers to binding data and the methods to manipulate that data together in a single unit (class).
Is it a good convention to declare all variables of a class private?
Yes, this restricts direct access by the code outside of the class. Use public methods such as getters and setters to grant access to internal variables.
Abstraction
Technique that focuses on revealing only the necessary details of a system and hiding irrelevant information to minimize complexity.
“Show what an object does and hide how it does it”
Polymorphism
Allows an object to have several different forms and behaviors.
Dynamic Polymorphism
AKA runtime polymorphism. Defines methods with same name, return type and parameters in base class and derived classes. Subclasses will need to override if there is something specific it needs to do.
Static Polymorphism
AKA compile-time polymorphism. Achieved by method or operator overloading.
Operator Overloading
”+” can be different depending on the data type. It will concatenate a string, but add two integers