Daniel's working notes

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: