Programming Interview Questions Flashcards
What is Object Oriented Programming?
A computer programming model
Organises software design around data and objects, rather than functions and logic
What are the benefits of OO Programming?
Beneficial for collaborative development
Code reusability, scalability and efficiency
What is a class?
User-defined data types
Act as the “blueprint” for objects, attributes and methods
What is an object?
Instances of a class, with specifically designed data
What are the main principles of OOP?
Encapsulation
Abstraction
Inheritance
Polymorphism
What is Encapsulation?
All important info is privately contained inside of an object
Each object is held privately within a defined class
Provides greater program security and avoids unintended data corruption
What is Abstraction?
Objects only reveal internal mechanisms that are relevant for the use of other objects - focuses on what an object does rather than how it does it
Simplifies complex systems by modelling them at a higher level of detail while hiding unnecessary implementation details
Helps developers easily make additional changes over time
What is Inheritance?
Classes can reuse code from other classes.
Allows developers to reuse common logic while maintaining a unique hierarchy
What is Polymorphism?
The ability to present the same interface for different data types (e.g. 1 method “Draw” for multiple children Square, Circle of a “Shape” class).
Reduces need for duplicate code
Examples of mainly OOP languages?
Java, Python, C++
Examples of pure OOP languages?
Ruby
JADE
Emerald
Downsides of OOP?
Overemphasises data component of software development
Can be complicated to write or take longer to compile
Alternative to OOP?
Functional programming e.g. Erlang
Many advanced programming languages allow users to combine models, e.g. JavaScript allows the combination of OOP and functional programming
What are design patterns?
Common and reusable solutions to problems given a certain context
What are anti-patterns?
“Bad” design patterns
Benefits & risks of design patterns?
Proven solution
Reusable
Expressive and Elegant
Prevent need for refactoring code
Lower size of codebase
Risk: might fall back on design pattern when there’s a better way to solve this particular problem
How many design patterns are there?
23
Types of software design patterns?
Creational
Behavioural
Structural
What are Creational Design Patterns?
Used for class instantiation
They can be Class creation or object-creational patterns
What are Structural Design Patterns?
Used for communication between objects
Designed to increase functionality of the classes involved
What are Behavioural Design Patterns?
Design Patterns that focus on how objects communicate and interact with each other
What are the architectural design patterns?
MVC Model View Controller
MVP Model View Presenter
MVVM Model View View Model
Describe MVC
Model = backend logic and data
View = interface components to display data
Controller = Input is directed here first
Benefits & risks of MVC
Provides separation of concern, separating front-end and back-end code
Makes it easier to update the application without interruption
Exposing the model to view can introduce security and performance concerns
Common for web apps
Describe MVP
Model = backend logic and data
View = input begins here
Presenter = processes request through the model and passes it back to the view
Benefits & risks of MVP
Common for Android apps, websites
Suited to make views reusable
Describe MVVM
Model = backend logic and data
View = input begins here
View-Model = only purpose is maintain the state of view and manipulate the model
Benefits & risks of MVVM
Used for mobile apps
Suited to help improve performance
Allows view-specific subsets of a model to be created, with the state and logic bound to the view.
What is a constructor?
A method used to initialise the state of an object
Method is called whenever an object is created
What is a destructor?
A method called when the object is destroyed
What is a virtual function?
A member function of a class
Its functionality can be overridden in its derived class
What is function overloading?
allows you to define multiple methods in a class with the same name but with different parameter lists.
Each overloaded method provides a different implementation of the same functionality
What is an abstract class?
A class that cannot be instantiated
Serves as a blueprint for other classes to inherit from
What is a ternary operator?
Equivalent to an if/else statement
What is the finalize method?
Performs cleanup on resources not being used
What are the argument types?
Call by Value - value passed only modified inside function
Call by Reference - value passed modified both inside and outside
What is method overriding?
Where a subclass’s method overrides the main class’s method. Uses same method name, parameter and type.
What is the difference between overloading and overriding?
Overloading is the same method with different arguments, overriding is a different method with the same argument in a child class
What are the access modifiers?
Private
Protected
Public
Friend
Protected Friend
What is a “sealed” class?
Access modifier which prevents other classes from inheriting from it.
How to call the base method without creating an instance?
Use static method
What is the difference between a structure and a class?
Structures are public by default and only stores data, classes are private and can store data and methods.
What is a pure virtual function?
A function which must be overridden in the derived class, but need not be defined.
What is the default access modifier in a class?
Private
What is coupling?
The degree of dependency of one class on another class; the ‘strength of relationship’ between modules.
Loose coupling is usually better than tight coupling
What is Loose Coupling?
Loose coupling = less interdependency, less coordination, less information flow.
Classes A and B are said to be ‘loosely coupled’ if the only knowledge that class A has about class B is what class B has exposed through its interface.
What is cohesion?
A measure of strength of relationship between the methods and data of a class
High cohesion is usually better than low cohesion
What are extension methods?
Allow you to add methods to existing types without creating new derived types, modifying the original code or using inheritance.
What is a static method?
A static method is a method that belongs to a class rather than an instance of a class, meaning you can call a static method without creating an object of the class.
What are some example of what you’d use Static methods for?
Mathematical operations, string manipulation methods, helper functions.