Object Oriented Flashcards
What is Object Oriented Programming?
Object Oriented Programming is a programming paradigm based on objects that contain data and procedures.
What are the Pillars of OOP?
Encapsulation
Inheritance
Polymorphism
Bonus - Abstraction
What is Encapsulation?
Encapsulation packages data and procedures up into a single unit. Removes access to all the information and only certain bits are exposed
What is Inheritance?
Classes can share and reuse code from other classes. A child class gains functionality from the parent class.
What is Polymorphism?
Using the object differently depending on how it is being used. Change the behaviour of implementation of a method based on the type using it or the parameters being used.
What is abstraction?
Abstraction (Bonus 4th Pillar) - Only expose what is necessary, keep the details hidden when possible. For example protect the internal state of an object by having a private field but a public property to set it.
Name the Solid Principles
Single Responsibility Principle Open/Close Principle Liscov’s Substitution Principle Interface Segregation Principle Dependency Inversion Principle
Explain Single Responsibility Principle
Single Responsibility Principle - “A software module should have one and only one reason to change”. A piece of code should only have one purpose and it should not try to do multiple things.
Explain Open/Close Principle
Open/Close Principle - “Code should be open for extension and closed to modification”. You should be able to change or add new behaviour without changing the source code. (E.g. adding parameters to a method so it can be reused or overriding/overloading methods)
Explain Liscov’s Substitution Principle
Liscov’s Substitution Principle - “Subtypes should be substitional for their base types”. Use the phrase “is substitutional for” (E.g. A cat (sub class) is substitutional for an animal (base class) as it will still fulfil the requirements of the base class).
Explain Interface Segregation Principle
Interface Segregation Principle - “Clients should not be forced to depend on methods they do not use”. Code should not have to inherit from an interface that contains methods that are not required so will not be properly implemented.
Explain Dependency Inversion Principle
Dependency Inversion Principle - “High level modulus should not have to depend on low level modules, both should depend on abstractions”. “Abstraction should not depend on details. Details should depend on abstractions” Code should be loosely coupled and classes should depend on abstract classes or interfaces to fulfil this principle.
What is Functional Programming?
Functional Programming is a programming paradigm based on the concept of mathematical functions and building functions for immutable variables.