OOP Flashcards
(28 cards)
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
Is static polymorphism or dynamic polymorphism more performant?
Static, because the binding is being done at compile time.
Steps to drawing a sequence diagram
- Identify the use case
- Identify the Actors and Objects
- Identify the order of actions
- Create the diagram
Fragment Frame
Allow us to represent conditional actions or loop sequences on a sequence diagram.
Steps to drawing an activity diagram
- Determine the actions of the system
- Determine the actors and their roles, and list them out
- Find the flow of each activity
- Create the diagram
Single Responsibility Principle (SRP)
Each class should be responsible for a single part or functionality of the system
Open Closed Principle (OCP)
Software components should be open for extension but closed for modification.
A system should improve easily without changing the code core.
Liskov Substitution Principle (LSP)
Objects of a superclass should be replaceable with objects of its subclasses without breaking the system
Interface Segregation Principle (ISP)
Make fine-grained interfaces that are client specific
Dependency Inversion Principle (DIP)
High level modules are not dependent on low-level modules.