SOLID principles
Single-responsibility principle
Open-closed principle
Liskov substitution principle
Interface seggregation principle
Dependency inversion principle
Every class should have only one responsibility
Software entities should be…
open for extension
closed for modification
Add new features only by adding new code —> means we have loosely coupled and maintainable code
Subtypes must be substitutable for their base types
A subtype should behave like a supertype (when using supertype methods)
Interface segregation principle
Many client-specific interfaces are better than one general-purpose interface
Invert the direction of dependency
High-level functions should not depend on low-level modules
Both should depend on abstractions
Four pillars of OOP
Abstraction
Encapsulation
Inheritance
Polymorphism
The ability of objects to take on multiple forms
Can be achieved through…
Inheritance, where a subclass can override or extend the methods of its superclass
Interfaces, which allow an object to implement multiple behaviors
Types of polymorphism in Java
Static
Dynamic
Parametric
Behavioural
Idea of bundling data and methods that operate on that data within a single unit, or object
This is meant to reduce complexity and increase modularity by allowing objects to be used as black boxes, with their internal workings hidden from the outside world (data-hidding)
Ability to focus on essential features of an object and ignore the details of its implementation
This allows developers to think about objects in terms of their interfaces and how they can be used, rather than how they are implemented
Allows one object to inherit the characteristics of another object
This means that an object can be based on an existing object, and can reuse its methods and variables, while also adding new functionality
Java keywords related to OOP?
class
package
import
extends
public
protected
private
interface
this
super
abstract
new
Disadvantages of inheritance
The fragility of the base class
The diamond problem
Strong class bindings and behavioural obligations
Liskov Principle
Calling super() is very aggravating
Last changed2 years ago