Data Transfer Object
Wrapping some variable that is used together into one object. In #swift, one practical example is when you need to pass some parameters into a function. Instead of defining a function that accept multiple argument, you can wrap all the property in struct and passed them all along
example:
// passing multiple arguments into function
func getProducts(page: Int, perPage: Int, categoryId: Int, shopId: Int) -> [Product] {
// implementation of get products
}
struct GetProductsParameters {
let page: Int
let perPage: Int
let categoryId: Int
let shopId: Int
}
func getProducts(parameters: GetProductsParameter) {
}
Linked Notes:
Today I learn
I believe that we can learn something new everyday, that’s why I set this page to record what I learn during the day.