What are the 4 Basics of OOP?
Encapsulation
Abstraction
Inheritance
Polymorphism
What is Encapsulation?
Controlling access to the state.
Encapsulation is when an object, containing properties and methods, encapsulates the how the properties/data/state is accessed via an interface - specific methods that have permission to access and or mutate properties.
EG1: An instance of a bank account class would hold within it the data of the current balance for that account. However it would be very dangerous if the balance could be accessed directly, so an interface provided might specify ‘withdraw’ & ‘deposit’ methods for specific processes.
EG2: Getters & Setters
What is Abstraction?
Hiding unnecessary details from the outside world.
Abstraction is when an object hides methods and properties not required by the outside worlds, only giving the bare minimum required by the consumer for successful use.
What is Inheritance?
Using a new class to extend the definition/functionality of an existing class.
EG1: If there were several types of bank accounts, a basic Account class could be implemented, and several other classes for specific accounts can inherit from the account class. E.G. Saving Account inherits from Saving Account.
What is Polymorphism?
Changing or adding to the functionality of a class by overriding and/or overloading methods.
What are the SOLID principles?
Single Responsibility Open-Closed Liskov Substitution Interface Segregation Dependency Inversion
What is the Single Responsibility Principle?
A class should hold a single responsibility to an actor. There should be never more than one reason for a class to change. If there is, a new class is required.
What is the Open-Closed Principle?
Software entities should be open for extension, but closed for modification.
What is the Liskov Substitution Principle
Subtypes must be substitutable for their base types.
What is the Inferface Segregation Principle?
Classes that implement interfaces, should not be forced to implement methods they do not use.
What is the Dependency Inversion Principle?
High-level modules should not depend on low level modules, rather both should depend on abstraction. Abstraction should not depend on details; rather detail should depend on abstraction.
How is Object Oriented code made DRY (not-repeating)?
What is Loose Coupling and why is it good?
When a class is used inside another class, it is considered a dependency - the class depends on the existence of another class to work. Loose coupling means that the state of the class instance (object) is never dependent on another class.
What traits indicate (unwanted) Tight Coupling?
What are good practices for method composition?
What type of class is a Model?
A model defines only raw fields of data (primary or other classes) for typing. This typically is used with database calls. These are also known as Plain Classes.
What type of class is a DTO?
A Data Transfer Object is used for transferring data between api’s. This might lack fields that are handled on the back-end (i.e. ID, created-on)