What is a Polymorphism
Front
Active users
2
All-time users
2
Favorites
0
Last updated
1 year ago
Date created
Jul 5, 2023
About Swift
(17 cards)
What is a Polymorphism
In Swift, polymorphism is typically achieved through inheritance and method overriding:
class Animal {
func makeSound() {
print("The animal makes a sound.")
}
}
class Cat: Animal {
override func makeSound() {
print("Meow!")
}
}
class Dog: Animal {
override func makeSound() {
print("Woof!")
}
}
// Usage:
let animal: Animal = Animal()
let cat: Animal = Cat()
let dog: Animal = Dog()
animal.makeSound() // Output: "The animal makes a sound."
cat.makeSound() // Output: "Meow!"
dog.makeSound() // Output: "Woof!"
What is a Subscript
Only for Class, allows you to define custom access patterns for instances of a type.
class MyList {
private var elements: [String] = []
subscript(index: Int) -> String {
get {
return elements[index]
}
set(newValue) {
elements[index] = newValue
}
}
}
// Usage:
let myList = MyList()
myList[0] = "Apple"
myList[1] = "Banana"
print(myList[0]) // Output: "Apple"
print(myList[1]) // Output: "Banana"
Why Swift is called a type-safe language
What is Inheritance and how affects Struct and Class
Classes support inheritance, allowing you to create hierarchies of related classes. A subclass can inherit properties and methods from its superclass and override or extend its behavior. Structs, however, do not support inheritance. They cannot be subclasses or superclasses, making them more suitable for simpler data structures or value-based operations.
What is Encapsulation in Swift
Bundling data and the methods that operate on that data into a single unit called an object.
In Swift, encapsulation is achieved through the use of access control modifiers (public
, internal
, private
, etc.) and the concept of properties and methods within a class or struct.
Which features ONLY a Struct support
Which features ONLY a Class support
Example of type casting:
class Vehicle {
var brand: String
init(brand: String) {
self.brand = brand
}
}
class Car: Vehicle {
var model: String
init(brand: String, model: String) {
self.model = model
super.init(brand: brand)
}
}
struct ContentView: View {
var body: some View {
let vehicle: Vehicle = Car(brand: "Tesla", model: "Model S")
if let car = vehicle as? Car {
Text("Brand: \(car.brand)\nModel: \(car.model)")
} else {
Text("Unknown vehicle type")
}
}
}
What is Mutability for Struct and Class
Struct is value type while a class is reference type, so when you create an instance of a struct, it is copied, and each copy is independent of the others. Modifications to one copy do not affect the others. In contrast, when you create an instance of a class, multiple references can point to the same instance. Modifying one reference will affect all other references to that instance.
Explain to me that I do not know anything, what is Swift
Swift is a modern multi-paradigm (OOP and POP) programming language that was introduced by Apple in 2014.
Which features a Class and Struct support
What is the difference in Identity and Comparisons between Struct and Class
Classes have identity, meaning that two class instances with the same property values are considered different objects. You can compare class instances using reference equality (=== and !==). Structs, on the other hand, do not have identity. Two struct instances with the same property values are considered equal, and you compare them using value equality (== and !=).
What is the difference in Memory Management between Struct and Class
Classes in Swift use Automatic Reference Counting (ARC) to manage memory. ARC keeps track of references to class instances and automatically deallocates them when they are no longer referenced. Structs, being value types, are automatically managed by the compiler, and memory management is handled implicitly.
Why Swift is POP
Protocols in Swift define a set of methods, properties, and other requirements that a type can adopt. A type can conform to one or multiple protocols, providing a way to express reusable behavior and create flexible code. Protocols in Swift can be used to achieve composition, reusability, and extensibility.e
Why using @StateObject instead of @ObservedObject
StateObject was introduced in Swift due to memory-leak issue caused originally by ObservedObject. The problem was caused by the deinitialization of a class instantiated with ObservedObject not deallocated from memory in a correct way when multiple instance of it where created inside code.
What is the main difference between Struct and Class
Struct is value type while a class is reference type
Why Swift is a multi-paradigm programming language
Swift is a multi-paradigm programming language that supports both object-oriented programming (OOP) and protocol-oriented programming (POP) paradigms.
What are Interfaces in Swift
In Swift, interfaces are defined using protocols. A protocol defines a blueprint of methods, properties, and other requirements that a class, struct, or enum must adhere to.
About Version Control
(8 cards)
What is Centralised Workflow
In this workflow, a single "master" branch serves as the central repository. Developers clone the repository, make changes in their local branches, and push their changes to the central repository. It's a simple workflow suitable for small teams or projects.
What is Gitflow Workflow
This workflow defines a specific branch structure, consisting of a "master" branch for stable releases, a "develop" branch for ongoing development, and feature branches for individual features or tasks.
What is Git
Git is a distributed version control system (DVCS) widely used for managing source code and tracking changes. It was created by Linus Torvalds, the creator of Linux
What is git and github
Git is a software maintained by linux while GitHub is a service owned by Microsoft.
What is Git Workflow
Git workflow refers to a set of guidelines and practices that outline how a team collaborates on a project using Git version control system.
What are Atomic Commits
It’s a software development practice where changes to a codebase are divided into small, self-contained units that can be independently committed.
What is Version Control
Is a system that allows multiple people to collaborate on a project while keeping track of changes made to the project's files over time.
What is Feature Branch Workflow
Each new feature or task is developed in a dedicated branch. Developers create a new branch from the "master" or "develop" branch, make their changes, and merge the branch back into the main branch.
About SOLID
(6 cards)
What is I of SOLID
Interface Segregation Principle (ISP): Clients should not be forced to depend on interfaces (protocols) they do not use. This principle promotes the idea of segregating interfaces (protocols) into smaller, more focused ones.
protocol Vehicle {
var brand: String { get set }
var model: String { get set }
var year: Int { get set }
var color: String { get set }
func start()
func stop()
func accelerate()
func brake()
func turnLeft()
func turnRight()
func switchLights(on: Bool)
func adjustSeat(position: Int)
func playMusic()
func lock()
func unlock()
// ... many more methods
}
/// THIS SHOULD BE AVOIDED, TOO MANY UNRELATED FUNCTIONS
What is O of SOLID
Open-Closed Principle (OCP): Software entities (classes, modules, functions) should be open for extension but closed for modification.
protocol Shape {
func area() -> Double
}
struct Rectangle: Shape {
let width: Double
let height: Double
func area() -> Double {
return width * height
}
}
struct Circle: Shape {
let radius: Double
func area() -> Double {
return Double.pi * radius * radius
}
}
struct AreaCalculator {
func calculateTotalArea(shapes: [Shape]) -> Double {
var totalArea: Double = 0.0
for shape in shapes {
totalArea += shape.area()
}
return totalArea
}
}
// Usage:
let rectangle = Rectangle(width: 5.0, height: 3.0)
let circle = Circle(radius: 2.5)
let areaCalculator = AreaCalculator()
let totalArea = areaCalculator.calculateTotalArea(shapes: [rectangle, circle])
print("Total area: \(totalArea)")
/// ADDING A NEW SHAPE LIKE A TRIANGLE DOES NOT CHANGE WHAT AreaCalculator DOES. SO AreaCalculator FOLLOW THE PRINCIPLES OCP
What is D of SOLID
High-level modules should depend on abstract interfaces or contracts rather than concrete implementations.
protocol Notification {
func send(message: String)
}
class EmailNotification: Notification {
func send(message: String) {
print("Sending email notification: \(message)")
}
}
class SMSNotification: Notification {
func send(message: String) {
print("Sending SMS notification: \(message)")
}
}
class NotificationService {
private let notification: Notification
init(notification: Notification) {
self.notification = notification
}
func notifyUser(message: String) {
notification.send(message: message)
}
}
// Usage:
let emailNotification = EmailNotification()
let smsNotification = SMSNotification()
let notificationService1 = NotificationService(notification: emailNotification)
notificationService1.notifyUser(message: "Hello, this is an email notification")
let notificationService2 = NotificationService(notification: smsNotification)
notificationService2.notifyUser(message: "Hello, this is an SMS notification")
What is SOLID
SOLID is an acronym that represents a set of five design principles for writing clean, maintainable, and scalable object-oriented software. These principles were introduced by Robert C. Martin (also known as Uncle Bob).
What is L of SOLID
Liskov Substitution Principle (LSP): Subtypes must be substitutable for their base types.
class Animal {
func makeSound() {
// Default implementation
}
}
class Dog: Animal {
override func makeSound() {
print("Woof!")
}
}
class Cat: Animal {
override func makeSound() {
print("Meow!")
}
}
func makeAnimalSound(animal: Animal) {
animal.makeSound()
}
// Usage:
let dog = Dog()
let cat = Cat()
makeAnimalSound(animal: dog) // Output: "Woof!"
makeAnimalSound(animal: cat) // Output: "Meow!"
/// IN THIS CASE makeAnimalSound USE Animal AS AN ACCEPTED TYPE AND NOT Dog OR Cat
What is S of SOLID
Single Responsibility Principle (SRP): A class should have only one reason to change.
class UserManager {
func createUser(username: String, password: String) {
// Code for creating a user and persisting it to a database
// ...
print("User created: \(username)")
}
func authenticateUser(username: String, password: String) {
// Code for authenticating a user
// ...
print("User authenticated: \(username)")
}
func deleteUser(username: String) {
// Code for deleting a user from the database
// ...
print("User deleted: \(username)")
}
}
// Usage:
let userManager = UserManager()
userManager.createUser(username: "john123", password: "password123")
userManager.authenticateUser(username: "john123", password: "password123")
userManager.deleteUser(username: "john123")
/// So every time we call a function we only change the calss for a specific reason
About Agile
(6 cards)
What is Scrum
Scrum is an Agile framework for managing complex projects.
What are the Artifacts in Scrum
What are the Roles in Scrum
What is a project
A temporary effort that a person or a team make to reach a common goal.
What are the Events in Scrum
What is Agile
Agile methodology is an iterative and flexible approach to project management and software development that emphasizes collaboration, adaptability, and continuous improvement.
About Design Patterns
(7 cards)
What’s the difference between the Controller and ViewModel
The Controller in MVC focuses on managing user input, updating the Model, and selecting the appropriate View. On the other hand, the ViewModel in MVVM acts as a data converter and presenter, providing data and behaviour to the View while abstracting the underlying Model.
What are MVC, MVVM and MVVM-C
Architectural Design Patterns
How MVVM-C works
The Coordinator in MVVM-C controls the flow between different ViewModels and coordinates the navigation stack. It helps separate the navigation logic from the ViewModel, allowing for better organization and testability.
How MVC works
MVC aims to achieve a clear separation of concerns, where each component has a specific responsibility.
How MVVM works
What is a Design Pattern
A design pattern is a general reusable solution to a commonly occurring problem in software design.
What other Design Patterns you know
About REST APIs
(4 cards)
What are the main response code for REST APIs operations
REST APIs use HTTP status codes to indicate the outcome of a request. For example, 200 OK indicates a successful request, 404 Not Found means the requested resource was not found, and 500 Internal Server Error indicates a server-side error.
Which kind of authorisation you can use to access to Rest API
OAuth is generally preferred for its flexibility, security, and ability to grant limited access to specific resources.
What are the common HTTP Verbs used with REST APIs
What are REST APIs
REST (Representational State Transfer) is an architectural style for designing networked applications.
REST APIs (Application Programming Interfaces) are a set of rules and conventions that allow systems to communicate and exchange data over the internet using the principles of REST.