OOP Flashcards
Inheritance vs Composition
Inheritance and composition are two programming techniques developers use to establish relationships between classes and objects. Whereas inheritance derives one class from another, composition defines a class as the sum of its parts.
Classes and objects created through inheritance are tightly coupled because changing the parent or superclass in an inheritance relationship risks breaking your code. Classes and objects created through composition are loosely coupled, meaning that you can more easily change the component parts without breaking your code.
Coupling & Cohesion
Name OOD principles that you know
Do you know SOLID principles (describe one of them)
Single Responsibility:
The class should have only one responsibility.
Open Closed:
The Entity should be Open to extension and close to modification.
Liskov Substitution:
This means you shouldn’t change the parent’s behavior, or if you switch the parent and child, everything should remain working. the Rectangle and square is the famous example.
Interface Segregation:
Every Interface should have the necessary method not much. means we shouldn’t force classes to implement empty functions or dummy functions.
Dependency Inversion:
Instead of creating a new dependency (object) inside your method, accept an Interface and make the client create a new dependency and pass it to you.
OOP?
The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.