SOLID etc Flashcards
5 SOLID principles?
- Single responsibility principle
- Open-closed principle
- Liskov substitution principle
- Interface segregation principle
- Dependency inversion principle
Single Responsibility Principle?
Each class, module, or function in your program should only do one job.
4 Principles of OOP?
- Abstraction
- Polymorphism
- Inheritance
- Encapsulation
Static Polymorphism?
The compiler identifies which method to call based on the parameters provided.
Dynamic Polymorphism?
- the subclass can override a method in the parent class that shares its name and parameters and provide a different functionality
- a subclass can be referenced as the superclass
Inner join?
Selects records that have matching values in both tables.
Outer join?
Returns all records when there is a match in left (table1) or right (table2) table records.
Left join?
Returns all records from the left table (table1), and the matching records from the right table (table2)
Open-closed Principle?
“Software entities … should be open for extension, but closed for modification.”
Entities should be able to be widely adapted but also remain unchanged.
Liskov Substitution Principle?
“Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.”
In other words, each subclass must maintain all behavior from the base class along with any new behaviors unique to the subclass. The child class must be able to process all the same requests and complete all the same tasks as its parent class.
Interface Segregation Principle?
“Many client-specific interfaces are better than one general-purpose interface.”
The interface segregation principle (ISP) requires that classes only be able to perform behaviors that are useful to achieve its end functionality. In other words, classes do not include behaviors they do not use.
Dependency Inversion Principle?
“One should depend upon abstractions, [not] concretions.”
High-level modules should not depend on low-level modules. Instead, both should depend on abstractions (interfaces)
Abstractions should not depend on details. Details (like concrete implementations) should depend on abstractions.
Encapsulation?
Encapsulation is the mechanism of hiding of data implementation by restricting access to public methods.
Instance variables are kept private and accessor methods are made public to achieve this.
Abstraction?
Abstract means a concept or an Idea which is not associated with any particular instance.
Using abstract class/Interface we express the intent of the class rather than the actual implementation.
Composition?
Design technique that implements a “has-a” relationship in classes (as opposed to an “is-a” relationship as in inheritance)
benefit - allows you to reuse code without modeling an is-a association, as one does with inheritance. This allows stronger encapsulation and makes your code easier to maintain.
a car is not an engine - it has one. a coffee machine has a grinder and a brewing unit, but it is neither.
ex: could have an “engine” class, then a “car” class. the car class could instantiate an engine object, then use
public Car(){ this.engine=new Engine(); engine.setMpg(30); }
to change that engine’s miles per gallon